正如你所看到的,我有这个wrapanel,它的事件叫做“KinectTitleButtonClick”;该事件适用于所有按钮。我想为每个按钮使用不同的方法,以便每个按钮执行不同的操作。
<WrapPanel VerticalAlignment="Center" x:Name="wrapPanel" Orientation="Vertical" k:KinectTileButton.Click="KinectTileButtonClick">
<!-- items for design layout. They will be replaced at runtime. -->
<k:KinectTileButton Label="1" Click="KinectTileButton_Click" />
<k:KinectTileButton Label="2"/>
<k:KinectTileButton Label="3"/>
<k:KinectTileButton Label="4"/>
<k:KinectTileButton Label="5" Click="KinectTileButton_Click_1" />
<k:KinectTileButton Label="6"/>
<k:KinectTileButton Label="7"/>
<k:KinectTileButton Label="8"/>
<k:KinectTileButton Label="9"/>
<k:KinectTileButton Label="10"/>
<Image Height="150" Name="image1" Stretch="Fill" Width="200" />
</WrapPanel>
在C#中,我有KinectTitleButtonClick的这种方法。
private void KinectTileButtonClick(object sender, RoutedEventArgs e)
{
var button = (KinectTileButton)e.Source;
var wineModel = button.Tag as WineModel;
var selectionDisplay = new SelectionDisplay(wineModel);
this.kinectRegionGrid.Children.Add(selectionDisplay);
e.Handled = true;
}
我尝试为按钮编号设置“KinectTitleButton_Click_1”方法。 5使用此代码,但它不起作用。它仍会触发相同的事件
private void KinectTileButton_Click_1(object sender, RoutedEventArgs e)
{
MessageBox.Show("Message");
}
答案 0 :(得分:0)
你尝试过这样的事吗?
private void KinectTileButtonClick(object sender, RoutedEventArgs e)
{
var button = (KinectTileButton)e.Source;
var wineModel = button.Tag as WineModel;
var selectionDisplay = new SelectionDisplay(wineModel);
this.kinectRegionGrid.Children.Add(selectionDisplay);
switch(button.Label.ToString())
{
case "5":
KinectTileButton_Click_1(sender, e);
break;
}
e.Handled = true;
}