C# 不起作用的装订
提前为我的英语道歉:) XAML标记:C# 不起作用的装订,c#,wpf,xaml,mvvm,binding,C#,Wpf,Xaml,Mvvm,Binding,提前为我的英语道歉:) XAML标记: <TreeView x:Name="treeRows" ItemsSource="{Binding TreeRows}"> <TreeView.ItemContainerStyle> <Style TargetType="TreeViewItem"> <Setter Property="IsExpanded" Value="True"></Setter&g
<TreeView x:Name="treeRows" ItemsSource="{Binding TreeRows}">
<TreeView.ItemContainerStyle>
<Style TargetType="TreeViewItem">
<Setter Property="IsExpanded" Value="True"></Setter>
</Style>
</TreeView.ItemContainerStyle>
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Children}">
<Label Content="{Binding DisplayColumn}"></Label>
<HierarchicalDataTemplate.ItemContainerStyle>
<Style TargetType="TreeViewItem">
<Style.Triggers>
<EventTrigger RoutedEvent="MouseRightButtonDown">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="ContextMenu.IsOpen">
<DiscreteBooleanKeyFrame KeyTime="0:0:0" Value="True"/>
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Style.Triggers>
<Setter Property="ContextMenu">
<Setter.Value>
<ContextMenu>
<MenuItem Header="Add" Command="{Binding CommandAddDataRow}"/>
<MenuItem Header="Update"/>
<MenuItem Header="Delete"/>
</ContextMenu>
</Setter.Value>
</Setter>
<Setter Property="IsExpanded" Value="True"></Setter>
</Style>
</HierarchicalDataTemplate.ItemContainerStyle>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
C#代码:
public class MainWindow
{
public ICommand CommandAddDataRow { get; set; }
public void AddDataRow(DataRow dataRow)
{
}
public MainWindow()
{
CommandAddDataRow = new Command<DataRow>(AddDataRow);
}
}
公共类主窗口
{
公共ICommand命令AddDataRow{get;set;}
公共无效AddDataRow(DataRow DataRow)
{
}
公共主窗口()
{
CommandAddDataRow=新命令(AddDataRow);
}
}
为什么除了这一行,装订到处都能用:
<MenuItem Header="Add" Command="{Binding CommandAddDataRow}"/>
退房。在答案的末尾,它展示了如何使用免费的Snoop实用程序在运行时识别任何错误的DataContext CommandAddDataRow=新命令(AddDataRow);什么类是Command?public Class Command:ICommandI不确定Command
类(您自己的?),但是您认为dataRow参数的参数来自哪里?在您的输出窗口中,可能有一些绑定错误。这里有一些错误。命令构造函数的定义是什么?