WPF ComboBox下拉部分出现在错误的地方 [英] WPF ComboBox DropDown part appears in the wrong place
问题描述
我在XAML窗口放了几个ComboBoxes。当我展开任何一个,DropDown部分出现在屏幕的左上角。
I put several ComboBoxes on a XAML window. When I expand any of them, the DropDown part appears on the upper left corner of the screen.
我使用Visual Studio 2008 C#Express。我不使用Visual Studio 2008(试用版),但我使用相同的FrameWork(3.5)。
I use Visual Studio 2008 C# Express. I don't remember this phenomenon when I used Visual Studio 2008 (Trial Version), though I use the same FrameWork (3.5).
推荐答案
这似乎是WPF中的一个错误。在我的情况下,我试图在另一个窗口的Loaded事件中打开一个窗口。为了解决这个问题,我设置一个定时器来触发,然后使用一个代理打开窗口(无法打开定时器事件中的窗口,因为打开窗口的调用线程必须是STA)。
This appears to be a bug in WPF. In my case, I was trying to open a window in the Loaded event of another window. To get around this, I set a timer up to fire, then used a delegate to open the window (cannot open the window in a timer event because the calling thread that opens a window must be STA).
编辑 - 计时器不是必需的 - 没有看到上面的答案只是排队它在调度程序...
Edit - timer isn't necessary - didn't see the answer above just queue it on the dispatcher...
private delegate void DelegateOpenWindow();
private DelegateOpenWindow m_DelegateOpenWindow;
private Timer loginTimer = new Timer(200);
private void MainWindow1_Loaded(object sender, RoutedEventArgs e)
{
// create delegate used for asynchronous call
m_DelegateOpenWindow= new DelegateOpenWindow(this.OpenWindow);
// start a timer to fire off the open window.
loginTimer.Elapsed += loginTimer_Elapsed;
loginTimer.Enabled = true;
}
void loginTimer_Elapsed(object sender, ElapsedEventArgs e)
{
loginTimer.Enabled = false;
this.Dispatcher.BeginInvoke(m_DelegateOpenWindow);
}
void OpenWindow()
{
MyWindow w = new MyWindow();
w.Owner = this;
w.ShowDialog();
}
这篇关于WPF ComboBox下拉部分出现在错误的地方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!