我Label.Content在WPF中不显示第一次出现的"_"字符.为什么?
<Window x:Class="WpfApplication3.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="148" Width="211">
<Grid>
<Label Content="L_abel" Height="28" HorizontalAlignment="Left" Margin="37,31,0,0" Name="label1" VerticalAlignment="Top" />
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)

设置时Label.Content ="L__abel":

项目中没有其他代码.
我试图在C#中处理WM_MOUSEMOVE消息.
从lParam获取X和Y坐标的正确方法是什么?这是一种IntPtr?
private void but_Click(object sender, RoutedEventArgs e)
{
(sender as Button).IsEnabled = false;
doSomeThing();//e.g run for more than 20 seconds
(sender as Button).IsEnabled = true;
}
Run Code Online (Sandbox Code Playgroud)
当我第一次按下按钮时它会禁用.然后启动doSomeThing()它包含UI代码或更新的一些UI变量.我的意思是,如果我在进行doSomeThing()中再次按下按钮,则but_Click此按钮启用后会再次触发事件.它保持触发事件的队列,即我按下的n次.
那么,如何在禁用按钮时阻止触发事件?请考虑在这种情况下'doSomething'包含UI控件绑定到代码.所以我们不能在这种情况下运行后台线程.帮我解决问题.
以下代码崩溃,但有异常:
MyWindow wnd = new MyWindow();
wnd.Show(); //here an exception occurs
Run Code Online (Sandbox Code Playgroud)
异常是相当奇怪的,但据我所知,它是.net中的一个错误
System.ComponentModel.Win32Exception (0x80004005): The operation completed successfully
at MS.Win32.UnsafeNativeMethods.GetDC(HandleRef hWnd)
at System.Windows.Interop.HwndTarget..ctor(IntPtr hwnd)
at System.Windows.Interop.HwndSource.Initialize(HwndSourceParameters parameters)
at System.Windows.Interop.HwndSource..ctor(HwndSourceParameters parameters)
at System.Windows.Window.CreateSourceWindow(Boolean duringShow)
at System.Windows.Window.CreateSourceWindowDuringShow()
at System.Windows.Window.SafeCreateWindowDuringShow()
at System.Windows.Window.ShowHelper(Object booleanBox)
at System.Windows.Window.Show()
Run Code Online (Sandbox Code Playgroud)
MyWindow对象是一个内部有一些矢量图形的窗口,但不是太多.此外,它已经在10-20个MyWindow对象已经打开和关闭时发生.
解决方案:原因是GDI对象泄漏.他们在我的低级代码中创建包含错误.所以,问题与MyWindow对象无关.
我按降序排列了SortedList.
public class MyComparer : IComparer<int>
{
public int Compare(int x, int y)
{
if (x.CompareTo(y) > 0)
return -1;
return 1;
}
}
class Program
{
static void Main(string[] args)
{
SortedList<int, bool> myList = new SortedList<int, bool>(new MyComparer());
myList.Add(10, true);
bool check = myList[10];//In this place an exception "Can't find key" occurs
}
}
Run Code Online (Sandbox Code Playgroud)
当没有我自己的IComparer创建SortedList时,代码工作正常,不会发生异常.
如果我只知道其标题的一部分及其className,我如何获得窗口的描述符?