我这里需要帮助。我试图在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行应该是禁用的编辑或不是?
我的Finaly是手动启动行编辑(每行都有一个链接),并使用每一行上的另一个链接确认行编辑,以便使用WCF服务保存数据。
发布于 2015-12-08 14:19:28
您可以手动定义列。
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding Path=YourField}"
IsReadOnly="{Binding IsReadonly}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>希望这能有所帮助
发布于 2015-12-08 18:21:06
你的xaml很适合我。我会查看你的IsReadonly属性。检查Visual输出中的绑定表达式路径错误。
https://stackoverflow.com/questions/34158048
复制相似问题