我的问题:
- 我有一个
DataGrid
带有按钮的 Xceed 列,它绑定到一个命令(该部分有效) - 现在我希望根据当前的某个值启用/禁用该按钮
DataRow
。 - 到目前为止,我可以获得命令绑定工作或
DataTrigger
取决于DataContext
我使用的命令,但不能同时进行。
我坚持以下代码:
<xcdg:Column FieldName="OpenInPiWebIdentifier"
Title="PiWeb Report"
VisiblePosition="6">
<xcdg:Column.CellContentTemplate>
<DataTemplate>
<Button DataContext="{Binding RelativeSource={RelativeSource Self}, Path=(xcdg:DataGridControl.ParentDataGridControl).DataContext}"
Content="Open PiWeb"
Command="{Binding OpenPiWebCommand}"
CommandParameter="{Binding DataContext.ResultData/PiWebReport, Mode=OneWay, RelativeSource={RelativeSource Self}}">
<Button.Style>
<Style TargetType="Button">
<Style.Triggers>
<DataTrigger Binding="{Binding PiWebReport}"
Value="{x:Null}">
<Setter Property="IsEnabled"
Value="False" />
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
</DataTemplate>
</xcdg:Column.CellContentTemplate>
</xcdg:Column>
以及命令的视图模型实现:
public ICommand OpenPiWebCommand
{
get
{
return _OpenPiWebCommand;
}
set
{
if (value != _OpenPiWebCommand)
{
_OpenPiWebCommand = value;
OnPropertyChanged("OpenPiWebCommand");
}
}
}
private ICommand _OpenPiWebCommand;
在构造函数中,我初始化命令:
OpenPiWebCommand = new RelayCommand(new Action<object>(OpenPiWeb));
该属性PiWebReport
属于一个类ResultDataV1
。所有数据都放入此属性中,该属性ResultData = new ObservableCollection<ResultDataV1>();
显示DataGrid
为列/行。所以,现在我可以访问属性值PiWebReport
或命令,这取决于我使用的上下文,但不能同时访问两者。
数据类:
public class ResultDataV1
{
public ResultDataV1(long dataId, DateTime dateTime, DateTime? endDateTime, string partId, string scanId, bool measurementNotVolumejoin, string piWebReport, FileInfo volumeFileInfo, FileInfo volumeVglFileInfo, DirectoryInfo volumeDirectoryInfo, string inspectionPlanName, string paletteName, AutomationStateEnum? automationState);
public AutomationStateEnum? AutomationState { get; }
public long DataId { get; }
public DateTime DateTime { get; }
public DateTime? EndDateTime { get; }
public string InspectionPlanName { get; }
public bool MeasurementNotVolumejoin { get; }
public string PaletteName { get; }
public string PartId { get; }
public string PiWebReport { get; }
public string ScanId { get; }
public List<SubResultDataV1> SubResults { get; }
public DirectoryInfo VolumeDirectoryInfo { get; }
public FileInfo VolumeFileInfo { get; }
public FileInfo VolumeVglFileInfo { get; }
}