2013-11-04 125 views
0

也许我误解了如何使用IValueConverter或数据绑定(很可能),但我目前正在尝试根据字符串的值设置DataGridTextColumn的IsReadOnly属性。这里是XAML:绑定IsReadOnly使用IValueConverter

<DataGridTextColumn Binding="{Binding Path=GroupDescription}" Header="Name" 
        IsReadOnly="{Binding Current, 
           Converter={StaticResource currentConverter}}"/> 

这里是我的转换器:

public class CurrentConverter : IValueConverter 
{ 
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
    { 
     string s = value as string; 
     if (s == "Current") 
     { 
      return false; 
     } 
     else 
     { 
      return true; 
     } 
    } 

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
    { 
     throw new NotSupportedException(); 
    } 
} 

目前,该列始终是可编辑,转换,似乎什么也不做。有没有人有一些想法,为什么发生这种情况?

+0

什么是问题/问题? – Szymon

+1

更新了问题的结尾,希望它不太含糊...... –

+0

IsReadOnly不可绑定。请参阅我的答案http://stackoverflow.com/questions/18443063/bind-datagrid-textbox-enable-based-on-checkbox-property/18444724#18444724 – Shoe

回答

0

而不是使用转换器,你可以用DataTrigger启用\禁用DataGridCell

<DataGridTextColumn Header="Name" Binding="{Binding GroupDescription}"> 
    <DataGridTextColumn.CellStyle> 
     <Style TargetType="DataGridCell"> 
      <Style.Triggers> 
       <DataTrigger Binding="{Binding Current}" Value="Current"> 
        <Setter Property="TextBlock.IsEnabled" Value="False" />          
       </DataTrigger>        
      </Style.Triggers> 
     </Style>      
    </DataGridTextColumn.CellStyle> 
</DataGridTextColumn> 
相关问题