我需要帮助。我试图在WPF DataGrid上禁用某些行编辑。 这是我的XAML:
<DataGrid ItemsSource="{Binding Path=Combustibles}" AutoGenerateColumns="False" SelectedItem="{Binding Path=SelectedCombustible}">
<DataGrid.Resources>
<Style TargetType="{x:Type DataGridRow}">
<Style.Triggers>
<DataTrigger Binding="{Binding IsReadOnly}" Value="True" >
<Setter Property="IsEnabled" Value="False" />
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.Resources>
</DataGrid>
这是我的ViewModel:
public class CombustiblesViewModel: BaseViewModel
{
public List<CombustiblesWCFModel> Combustibles{ get; set; }
private CombustiblesWCFModel _selectedcombustible = new CombustiblesWCFModel();
public CombustiblesViewModel()
{
Combustibles = _svc.Combustibles_List(sTicket);
Combustibles[1].IsReadOnly = true;
}
public CombustiblesWCFModel SelectedCombustible
{
get
{
return this._selectedcombustible;
}
set
{
this._selectedcombustible = value;
NotifyOfPropertyChange("SelectedCombustible");
}
}
}
我的模特有一个属性:
public partial class CombustiblesWCFModel
{
public Boolean IsReadOnly { get; set; }
}
因此,第1行应禁用edditing或isn&#t; t?
My Finaly boal是手动启动行编辑(每行有一个链接)并使用WCF服务保存数据,确认行编辑与每行上的另一个链接。
答案 0 :(得分:2)
您可以手动定义列
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding Path=YourField}"
IsReadOnly="{Binding IsReadonly}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
希望这有帮助
答案 1 :(得分:0)
你的xaml对我很好。我会查看你的IsReadonly财产。检查Visual Studio输出中的绑定表达式路径错误。