当IsEnabled更改时,WPF组合框文本转换器

时间:2013-07-23 12:38:18

标签: wpf combobox converter isenabled

Text设置为false时,我将更改组合框的IsEnabled属性,并且当IsEnabled为真时,它可以从项源中手动选择字段,这可能吗?

XAML:

<ComboBox Name="cmbIntervals"
                        Grid.Row="5"
                        Grid.Column="1"
                        Width="150"
                        HorizontalAlignment="Left"
                        VerticalAlignment="Top"
                        IsEnabled="{Binding ElementName=chkBox,
                                              Path=IsChecked}"
                        ItemsSource="{Binding Source={x:Static res:Parameters.Instance},
                                                Path=Intervals}"
                        Text="{Binding [Intervals],                                         Mode=TwoWay,
                                         UpdateSourceTrigger=PropertyChanged}" >
              <ComboBox.Style>
                    <Style TargetType="{x:Type ComboBox}">                       
                        <Style.Triggers>
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter Property="Text" Value="1"/>                            
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </ComboBox.Style>
              </ComboBox>

1 个答案:

答案 0 :(得分:0)

只需登入ViewModel

即可
if(!IsChecked)
{
TextProperty="1"; //Propery to bind to ComboBox Text
}