我是WPF的新手。我已经在WPF中使用“树形视图”创建了一个静态菜单。但是左菜单单击事件未触发。我有以下代码。
<UserControl x:Class="navigationApp.dashboard"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:navigationApp"
mc:Ignorable="d"
d:DesignHeight="650" d:DesignWidth="1120">
<Grid >
<TreeView>
<TreeViewItem Header="Dashboard" Name="menuDashboard" MouseLeftButtonDown="menuDashboard_MouseLeftButtonDown"/>
<TreeViewItem Header="Customer">
<TreeViewItem Header="Customer Listing" Name="menuCustomerList" MouseLeftButtonDown="menuCustomerList_MouseLeftButtonDown"/>
<TreeViewItem Header="Add New Customer" Name="menuCustomerReg" MouseLeftButtonDown="menuCustomerReg_MouseLeftButtonDown"/>
</TreeViewItem>
<TreeViewItem Header="Settings"/>
</TreeView>
</Grid>
</UserControl>
是否需要其他代码?
答案 0 :(得分:1)
您可能可以使用单个class Ex{
String id;
double version;
public Ex(String id, double version) {
this.id = id;
this.version = version;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public double getVersion() {
return version;
}
public void setVersion(double version) {
this.version = version;
}
}
public class Main{
public static void main(String[] args) {
List<Ex> list = new ArrayList<Ex>();
Ex rec1 = new Ex("HR3-A1234", 0.00);
Ex rec2 = new Ex("HR3-A1234", 0.01);
Ex rec3 = new Ex("HR3-A1234", 1.00);
Ex rec4 = new Ex("HR3-A2345", 0.00);
Ex rec5 = new Ex("HR3-A2345", 0.01);
Ex rec6 = new Ex("HR3-A3456", 0.01);
Ex rec7 = new Ex("HR3-A3456", 1.00);
Ex rec8 = new Ex("HR3-A4567", 0.01);
list.add(rec1);
list.add(rec2);
list.add(rec3);
list.add(rec4);
list.add(rec5);
list.add(rec6);
list.add(rec7);
list.add(rec8);
}
}
事件处理程序:
SelectedItemChanged
XAML:
private void TreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
TreeViewItem clickedTreeViewItem = e.NewValue as TreeViewItem;
//...
}