我试图在指定的索引后删除字符串中的所有字符.我确信必须有一个简单的功能才能做到这一点,但我不确定它是什么.我基本上是在寻找与c#的string相同的javascript.
我试图在我的WinRT应用程序中关闭MessageDialog.我注意到如果我试图一次显示两个消息对话框,我得到一个UnauthorizedAccessException.为了避免这种情况,我想关闭现有的消息对话框,如果它是打开的.我用它来显示对话框:
MessageDialog md = new MessageDialog(" ");
private void MessageBox(string s)
{
Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
md.Content = s;
//CLOSE HERE
md.ShowAsync();
}
);
}
Run Code Online (Sandbox Code Playgroud)
我怎么关闭它?
我想在TextBox中抑制一个键击.要禁止Backspace之外的所有击键,我使用以下内容:
private void KeyBox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
e.Handled = true;
}
Run Code Online (Sandbox Code Playgroud)
但是,当按下的键是Backspace时,我只想抑制键击.我使用以下内容:
if (e.Key == System.Windows.Input.Key.Back)
{
e.Handled = true;
}
Run Code Online (Sandbox Code Playgroud)
但是,这不起作用.选择开始背后的字符仍然被删除.我在输出中得到"TRUE",因此正在识别Back键.如何阻止用户按退格键?(我的理由是我想在某些情况下删除单词而不是字符,所以我需要自己处理后退键).)
有谁知道一个好的免费API来获取邮政编码的坐标?我目前正在使用的是
http://forecast.weather.gov/zipcity.php?inputstring=00000
Run Code Online (Sandbox Code Playgroud)
但这不是真正的API,可能会发生变化。我不需要确切的位置,此信息的目的是查找日出/日落时间。
我想在桌面上创建一个带有自定义图标的互联网快捷方式(url文件).要创建快捷方式,我目前使用:
private void CreateShortcut(string name, string url)
{
string deskDir = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
using (StreamWriter writer = new StreamWriter(deskDir + "\\" + name + ".url"))
{
writer.WriteLine("[InternetShortcut]");
writer.WriteLine("URL=" + url);
writer.Flush();
}
}
Run Code Online (Sandbox Code Playgroud)
但是此代码未设置自定义图标.我该如何设置图标?
我试图从后面的代码中的父页面调用IFrame中的脚本.我用来调用函数的C#:
protected void Page_Load(object sender, EventArgs e)
{
...
string scr = "document.getElementById('mapframe').contentWindow.addPoint(0, 0);"
ClientScript.RegisterStartupScript(GetType(), Guid.NewGuid().ToString(), scr , true);
}
Run Code Online (Sandbox Code Playgroud)
iFrame的HTML:
<iframe name="mapframe" id="mapframe" src="Map.html" style="width:100%;height:360px;"></iframe>
Run Code Online (Sandbox Code Playgroud)
和IFrame中的Javascript:
function addPoint(lat, lon) {
var myLatlng = new google.maps.LatLng(lat, lon);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: "Hit"
});
}
Run Code Online (Sandbox Code Playgroud)
但是,这会导致此错误:"无法获取未定义或空引用的属性'addPoint'".导致此错误的原因是什么?我已检查以确保contentWindow不为null.
我正在尝试下载图像,并在完成时触发事件.我用这个:
BitmapImage btest = new BitmapImage(new Uri("http://www.google.com/images/srpr/logo4w.png"));
btest.ImageOpened += btest_ImageOpened;
void btest_ImageOpened(object sender, RoutedEventArgs e)
{
throw new NotImplementedException();
}
Run Code Online (Sandbox Code Playgroud)
但是,该ImageOpened事件不会发生.如果我将Image Control的源设置为BitmapImageusing:
image.Source = btest;
Run Code Online (Sandbox Code Playgroud)
它确实很火.ImageOpened除非将BitmapImage发件人设置为图像的来源,为什么不会触发事件?
我试图用三个单独的WebClient下载三个文件.我用这个:
void client1_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
MessageBox.Show("CLIENT1");
}
void client2_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
MessageBox.Show("CLIENT2");
}
void client3_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
MessageBox.Show("CLIENT3");
}
private void mwindow_Loaded(object sender, RoutedEventArgs e)
{
string rand = new Random().Next().ToString();
WebClient client1 = new WebClient();
client1.OpenReadCompleted += client1_OpenReadCompleted;
client1.OpenReadAsync(new Uri("http://www.example.com/file.exe?r=" + rand));
WebClient client2 = new WebClient();
client2.OpenReadCompleted += client2_OpenReadCompleted;
client2.OpenReadAsync(new Uri("http://www.example.com/file.exe?r=" + rand));
WebClient client3 = new WebClient();
client3.OpenReadCompleted += client3_OpenReadCompleted;
client3.OpenReadAsync(new Uri("http://www.example.com/file.exe?r=" + rand));
}
Run Code Online (Sandbox Code Playgroud)
使用它时,无论我做什么,三个WebClient中只有两个会完成.使用此代码,我得到两个消息框"CLIENT1"和"CLIENT2",但"CLIENT3"永远不会出现.不会抛出异常或任何异常.什么都没发生.如果我扭转Web客户的订单,client3和client2工作,但不是client1 …
我正在尝试为Windows Phone 8开发一个基于Web的应用程序.我有一个带有两个div的网页position:fixed.如果我在Windows Phone上打开Internet Explorer应用程序并导航到我的网页,则固定元素将完美显示.但是,当我WebBrowser在本机应用程序中查看WP8控件中的网页时,position:fixed样式将被完全忽略.
我还注意到我所有的css转换也只能在完整的Internet Explorer应用程序中运行.这不是一个大问题,但缺乏固定定位是一个真正的问题.为什么WebBrowser这样做,有没有解决方法?
我知道固定定位和转换在WP7中不起作用,我想知道WP8 WebBrowser控件是否具有与WP7 WebBrowser控件相同的代码.
我想弄清楚如何在我的XNA游戏中创建一个Timer.我正在使用MonoGame并开发用于Windows 8 RT.当我使用以下方法检查GameTime.ElapsedGameTime时:
protected override void Update(GameTime gameTime)
{
TimeSpan mean = gameTime.ElapsedGameTime - last;
Debug.WriteLine(gameTime.ElapsedGameTime.ToString());
...
Run Code Online (Sandbox Code Playgroud)
ElapsedGameTime始终为00:00:00.0166666.它不会改变这个值.为什么会这样?