1

グリッドが正しくバインドされているのは、コード ビハインドの条件に基づいて、Column2 に含まれるすべてのコンボ ボックスを無効にするか、読み取り専用にすることだけです。グリッドがレンダリングされた後、このコンボボックスを含む 10 行を取得するとします。これらの 10 行すべてでコンボボックス列を無効にする必要があります。

<DataGridTextColumn Binding="{Binding Value1}" Header="Column1" IsReadOnly="True"/>
    <DataGridTemplateColumn Header="Column2">
        <DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
                <ComboBox SelectedItem="{Binding MySelectedItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" ItemsSource="{Binding MyComboItemSource}" >                                       
                </ComboBox>
            </DataTemplate>
        </DataGridTemplateColumn.CellTemplate>
    </DataGridTemplateColumn>
</DataGridTextColumn>
4

2 に答える 2

1

コード ビハインドで bool プロパティを作成し、xaml でコンボボックスの isEnabled プロパティにバインドするだけです。

コードビハインド

private bool _Disable;

        public bool Disable
        {
            get { return _Disable; }
            set
            {
                _Disable= value;
                OnPropertyChanged("Disable");
            }
        }

Xaml

<ComboBox IsEnabled="{Binding Disable,Mode=TwoWay,RelativeSource={RelativeSource AncestorType=Window}}" SelectedItem="{Binding MySelectedItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" ItemsSource="{Binding MyComboItemSource}" >
于 2013-10-04T10:32:54.243 に答える
0

コンボボックスの IsEnabled プロパティに Converter を使用できます。

何かのようなもの

<ComboBox IsEnabled ={Binding Path=XXXX, Converter = {StaticResource MyConverter}} .... />

MyConverter は、必要なプロパティをチェックし、false または true を取得します。このようなもの:

 public class MyConverter: IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if(value!=null)
{
     if((int) value==1)
return true;
else return false;
}

        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
于 2013-10-04T10:26:58.963 に答える