2016-02-09 196 views
0

我想根據從數據庫返回的程序禁用[只讀] a DataGridCell。我使用下面的代碼,但它不工作WPF禁用DataGrid單元格

<DataGridTextColumn Width="SizeToCells" x:Name="amountColumn" Header="Amount" Binding="{Binding Amount}" MinWidth="100" > 
    <DataGridTextColumn.CellStyle> 
     <Style TargetType="DataGridCell"> 
      <Style.Triggers> 
       <DataTrigger Binding="{Binding RoleName}" Value="Payment Authoriser" > 
        <Setter Property="Background" Value="#DDA0DC" /> 
        <Setter Property="ToolTip" Value="Please Add Amount" /> 
       </DataTrigger> 
      </Style.Triggers> 
     </Style> 
    </DataGridTextColumn.CellStyle> 
</DataGridTextColumn> 
<Setter Property="DedableThisCell" Value="Please DesableMe" /> 

GridCell將只有寫在RoleName="Payment Maker"RoleName還有什麼別的,這將是隻讀的。

回答

0

你試過類似的東西嗎?

<DataTrigger Binding="{Binding RoleName}" Value="Payment Maker" > 
     <Setter Property="IsEnabled" Value="True" /> 
</DataTrigger> 
+0

您好我想保持ROLENAME =「付款機」,比真否則爲假 – user3624511

+0

@ user3624511你可以逃脫禁用整個'DataGrid'?你可以在'DataGrid'上試試'IsEnabled = false',看看'DataTrigger'是否啓用'Cell'? – CBreeze

+1

我做類似的東西 !好的方法 user3624511