1
我在列表框中創建靜態上下文菜單。顯示上下文菜單,但其單擊事件不起作用。wpf中列表框的上下文菜單事件
<Canvas x:Name="LeftCanvas" Grid.Column="0" Grid.Row="1" Margin="5,0,0,0">
<StackPanel>
<TextBlock Text="Unseated Guests" Background="Blue" Foreground="White" FontFamily="Verdana" FontSize="11" FontWeight="Bold" Height="17" Width="150" HorizontalAlignment="Left" TextAlignment="Center" Padding="0,4,5,2"></TextBlock>
<ListBox x:Name="UnseatedPersons" ItemsSource="{Binding}" Height="218" Width="150" BorderBrush="Blue" BorderThickness="2" HorizontalAlignment="Left" Padding="3,2,2,2" src:FloorPlanClass.DragEnabled="true" MouseEnter="UnseatedPersons_MouseEnter"
MouseLeave="SourceListBox_MouseLeave">
<ListBox.ItemTemplate>
<DataTemplate>
<DockPanel>
<DockPanel.Resources>
<ContextMenu x:Key="ctxtmenu">
<MenuItem Header="Archive Info" Click="bt_click"></MenuItem>
<MenuItem Header="Guest Info"></MenuItem>
</ContextMenu>
</DockPanel.Resources>
<Image Name="imgPerson" Source="{Binding ImagePath}" ContextMenu="{StaticResource ctxtmenu}"></Image>
<TextBlock Name="txtPersonName" Text="{Binding PersonName}" Padding="2,4,0,0" ContextMenu="{StaticResource ctxtmenu}"></TextBlock>
</DockPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</Canvas>
我該如何解決這個問題?
?大多數情況下,其他面板之一是更好的選擇。 – svick
意味着我必須移除到canvas.actually它添加了其他應用程序的控制 – user644194
您的代碼爲我工作後,我刪除了'src:FloorPlanClass.DragEnabled'和事件處理程序屬性。當我點擊圖片時,我會顯示上下文菜單。 – svick