我有一個MenuItem誰的ItemsSource是數據綁定到一個簡單的字符串列表,它顯示正確,但我很努力地看到我如何處理點擊事件爲他們!我如何處理WPF中的數據綁定菜單中的點擊事件
下面是一個簡單的應用程序,演示了:
<Window x:Class="WPFDataBoundMenu.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<Menu>
<MenuItem Header="File" Click="MenuItem_Click" />
<MenuItem Header="My Items" ItemsSource="{Binding Path=MyMenuItems}" />
</Menu>
</Grid>
using System.Collections.Generic;
using System.Windows;
namespace WPFDataBoundMenu
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public List<string> MyMenuItems { get; set;}
public Window1()
{
InitializeComponent();
MyMenuItems = new List<string> { "Item 1", "Item 2", "Item 3" };
DataContext = this;
}
private void MenuItem_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("how do i handle the other clicks?!");
}
}
}
非常感謝!
Chris。
這仍然導致中央處理程序,它接通了SomeProperty值。不是嗎? – Gishu 2008-12-01 19:01:22