2011-02-05 142 views
0

我動態創建一個框架並將其添加到堆棧面板的子項中。鼠標事件工作正常,但由於某種原因停止。任何幫助表示讚賞。這裏就是我創建它們:WPF框架內部StackPanel不會觸發事件

Frame newFrame = new Frame(); 
Page current = Globals.Static.GetCurrentProcess() as Page; 
current.Width = 1199; // Doing this here forces the scaletransform to shrink entire app -- must be done on the page 
newFrame.Content = current; 
newFrame.Width = 384; 
newFrame.Height = 288; // Doing this here will limit the shrunk app's height -- must be done on the frame 
newFrame.MouseDoubleClick += new MouseButtonEventHandler(newFrame_MouseDoubleClick); 
newFrame.Name = current.Title + "_Frame"; 
this.stackRunning.Children.Add(newFrame); 

Separator newSeparator = new Separator(); 
newSeparator.Name = current.Title + "_Separator"; 
this.stackRunning.Children.Add(newSeparator); 

stackRunning是在主窗口中的空白StackPanel。在事件處理程序中,我只是創建一個變量,然後我停下來。它永遠不會起火。

回答

0

您的鼠標點擊可能會被子元素吞噬,但使用PreviewMouseDoubleClick可能會有所幫助。

+0

我試過MouseDown,PreviewMouseDown和PreviewMouseDoubleClick ...都沒有火。這很奇怪......這是工作,突然停止。 – 2011-02-05 16:01:03

2

由於沒有背景,您的框架可能無法擊中。你有沒有嘗試設置背景?

+0

是的,我將背景設置爲純色......仍然不行。 – 2011-02-05 16:01:27

+0

可能不是OP的問題,但絕對是我的。謝謝! – devuxer 2011-11-17 01:59:30

0

我發現了原因。我爲scrollviewer添加了一些新的重載滾動條代碼,並且它吸引了很多東西。多謝你們。