如何在WPF中绑定 - 2个组合框 [英] How to bind in WPF - 2 combo boxes

查看:69
本文介绍了如何在WPF中绑定 - 2个组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个组合框 addCC_cmbCollected & addCC_cmbQuality 的。根据在 addCC_cmbCollected 中选择的项目,我想禁用其他组合框( addCC_cmbQuality )并从这个组合框中选择一个特定的项目,因为我将值存储到XML,我希望如果禁用它,默认值将是NA,而不是在启用时显示最新值。 />


I have 2 combo boxes addCC_cmbCollected & addCC_cmbQuality. Depending on the item selected in addCC_cmbCollected which is either Yes or No I want to disable the other combo box (addCC_cmbQuality) and select a particular item from this combo box, as I am storing the values to an XML and I want that if this is disabled the default value would be "NA" instead of showing the latest value when this was enabled.

<ComboBox x:Name="addCC_cmbQuality" Grid.Column="7" HorizontalAlignment="Left" Margin="214,260,0,0" VerticalAlignment="Top" Width="111" RenderTransformOrigin="0.423,0.409" Height="23" Loaded="cmbQuality_Loaded">
    <ComboBox.Style>
        <Style TargetType="{x:Type ComboBox}">
            <Setter Property="IsEnabled" Value="True" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=SelectedValue, ElementName=addCC_cmbCollected}" Value="No">
                    <Setter Property="IsEnabled" Value="False" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </ComboBox.Style>
</ComboBox>





我尝试了什么:



我设法禁用了addCC_cmbQualit y combobox但无法找到显示特定值/项目的方法。



What I have tried:

I have managed to disable the addCC_cmbQuality combobox but cannot find a way to show a particular value/item.

推荐答案

尝试这样的事情(我使用了几个按钮在启用/禁用之间切换 - 你可能会在OnSelectionChanged事件中想要这个)

Try something like this (I used a couple of buttons to toggle between enabled/disabled - you will probably want this in the OnSelectionChanged event)
private void Disable_Click(object sender, RoutedEventArgs e)
{
    Job.Items.Add("NA");
    Job.SelectedValue = "NA";
    Job.IsEnabled = false;
}
private void Enable_Click(object sender, RoutedEventArgs e)
{
    Job.Items.Remove("NA");
    Job.IsEnabled = true;
}


这篇关于如何在WPF中绑定 - 2个组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆