/ / Wpf में अन्य कॉम्बोक्स के आधार पर कॉम्बोक्स को अक्षम कैसे करें - wpf, wpf-control

Wpf - wpf, wpf-control में अन्य combobox के आधार पर combobox को अक्षम कैसे करें

मेरे पास एक ही wpf विंडो में 2 कॉम्बोक्स है। पहले कॉम्बोक्स में पहला आइटम सिलेवसन है और इसे डिफ़ॉल्ट रूप से चुना जाता है (isselected = true)। अब मुझे दूसरी कैंडोबॉक्स को निष्क्रिय करने की आवश्यकता है यदि पहले कॉम्बोक्स का पहला आइटम चुना गया है अन्यथा सक्षम है।

मैंने कोशिश की,

यदि (absversion.selectedindex! = 0)

Secondcombo.isenabled = false: // यहां मुझे अशक्त संदर्भ अपवाद मिल रहा है

अन्य Secondcombo.isenabled = true:

पेज_लोड घटना में मैं हूँ,

Secondcombo.isenabled = false // ताकि सेकंडकॉम्बो डिफॉल्ट वेन लोड करके अक्षम हो जाएगा।

किसी को भी मेरी मदद कर सकते हैं, यह करने के लिए।

उत्तर:

जवाब के लिए 3 № 1

मैं XAML में कोडबाइंड की तुलना में ऐसा करने के लिए अधिक इच्छुक हूं:

<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ComboBox Grid.Row="0" x:Name="ComboBox1">
<ComboBoxItem>Item 1</ComboBoxItem>
<ComboBoxItem>Item 2</ComboBoxItem>
<ComboBoxItem>Item 3</ComboBoxItem>
</ComboBox>
<ComboBox Grid.Row="1">
<ComboBox.Style>
<Style TargetType="{x:Type ComboBox}">
<Setter Property="IsEnabled" Value="True" />
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=ComboBox1, Path=SelectedIndex}" Value="0">
<Setter Property="IsEnabled" Value="False" />
</DataTrigger>
</Style.Triggers>
</Style>
</ComboBox.Style>
<ComboBoxItem>Item 1</ComboBoxItem>
<ComboBoxItem>Item 2</ComboBoxItem>
<ComboBoxItem>Item 3</ComboBoxItem>
</ComboBox>
</Grid>