我有一个我想在我的数据网格中使用的上下文菜单。在每一行,我都希望菜单显示
是否可以根据属性IsRunToTest设置每行显示两个菜单项之一?我想知道是否需要将我的IsRunToTest属性设置为索引器,但不确定如何执行此操作并使其适用于每一行。
<DataGrid ItemsSource="{Binding TestResults}"
SelectedItem="{Binding SelectedTestResult}">
<DataGrid.ContextMenu>
<ContextMenu>
<MenuItem Header="Run To Selected Test"
Command="{Binding RunToSelectedTestAction}"
Visibility="{Binding IsRunToTestSet,
Converter={StaticResource BoolToVisibilityConverter},
ConverterParameter=Visible}" />
<MenuItem Header="Remove Run To Selected Test"
Command="{Binding RemoveRunToSelectedTestAction}"
Visibility="{Binding IsRunToTestSet,
Converter={StaticResource BoolToVisibilityConverter},
ConverterParameter=Collapsed}" />
</ContextMenu>
</DataGrid.ContextMenu>
...Defined Columns
</DataGrid>
ViewModel Properties
public ObservableCollection<TestResultsModel> TestResults
{
get
{
return this.testResults;
}
set
{
this.testResults = value;
this.NotifyPropertyChanged(m => m.TestResults);
}
}
public TestResultsModel SelectedTestResult
{
get
{
return this.selectedTestResult;
}
set
{
this.selectedTestResult = value;
this.NotifyPropertyChanged(m => m.SelectedTestResult);
}
}
public bool IsRunToPCodeSet
{
get
{
return this.SelectedTestResult.IsRunToPCodeSet;
}
set
{
this.SelectedTestResult.IsRunToPCodeSet = value;
this.NotifyPropertyChanged(m => m.IsRunToPCodeSet);
}
}