Как отключить несколько элементов в wpf на основе выбора поля со списком? - PullRequest
0 голосов
/ 25 сентября 2018

Мне нужно отключить ComboBox и Label на основе другого ComboBox выбора.

У меня есть следующий код для отключения комбинированного списка, но дополнительно мне нужно отключить метку с помощьюполе со списком.

XAML

<Label  Style="{StaticResource LabelTitle}"   Content="F"  x:Name="Label_FType" Margin="25.087,24.592,-94.145,7.6" d:LayoutOverrides="Width, Height"  />
<ComboBox x:Name="Combo_F_Type" Style="{StaticResource ComboBox}" IsSynchronizedWithCurrentItem="True" Margin="46.145,29.692,0,12.5" Grid.Column="1" 
          Width="226.199" HorizontalAlignment="Left" d:LayoutOverrides="Height">
    <ComboBoxItem Content="Select Type" IsSelected="True" />
    <ComboBoxItem Content="F1" />
    <ComboBoxItem Content="F2" />
    <ComboBoxItem Content="F3" />
</ComboBox> 

<Label Style="{StaticResource LabelTitle}" Content="S" x:Name="Label_SType" Margin="25.087,3.1,-94.145,29.092" d:LayoutOverrides="Width, Height" Grid.Row="1" />
<ComboBox Style="{StaticResource EnableSType}" IsSynchronizedWithCurrentItem="True" Margin="46.145,8.2,0,33.992" Grid.Column="1" Width="226.199"
          HorizontalAlignment="Left" d:LayoutOverrides="Height" Grid.Row="1" >
   <ComboBoxItem Content="Select Type" IsSelected="True" />
   <ComboBoxItem Content="S1" />
   <ComboBoxItem Content="S2" />
   <ComboBoxItem Content="S3" />
   <ComboBoxItem Content="S4" />
</ComboBox> 

XAML STYLE

<Style TargetType="{x:Type ComboBox}" x:Key="EnableSType">
    <Setter  Property="FontSize" Value="14" />
    <Setter Property="Height" Value="30"/>
    <Setter Property="FontWeight" Value="Bold"/>
    <Setter Property="IsEnabled" Value="False" />
    <Style.Triggers>
        <DataTrigger Binding="{Binding ElementName=Combo_FType, Path=SelectedIndex}" Value="3">
            <Setter Property="IsEnabled" Value="True" />
        </DataTrigger>
    </Style.Triggers>
</Style>

Может кто-нибудь помочь мне?

Ответы [ 2 ]

0 голосов
/ 25 сентября 2018

Вы можете привязать свойство Labels IsEnabled к свойству IsEnabled ComboBox.

<Label IsEnabled="{Binding ElementName=Combo_S_Type, Path=IsEnabled}" Style="{StaticResource LabelTitle}"   Content="S" x:Name="Label_SType" Margin="25.087,3.1,-94.145,29.092" d:LayoutOverrides="Width, Height" Grid.Row="1"  />
       <ComboBox x:Name="Combo_S_Type" Style="{StaticResource EnableSType}" IsSynchronizedWithCurrentItem="True" Margin="46.145,8.2,0,33.992" Grid.Column="1" Width="226.199" HorizontalAlignment="Left" d:LayoutOverrides="Height" Grid.Row="1" >
           <ComboBoxItem Content="Select Type" IsSelected="True" />
           <ComboBoxItem Content="S1" />
           <ComboBoxItem Content="S2" />
           <ComboBoxItem Content="S3" />
           <ComboBoxItem Content="S4" />
      </ComboBox> 
0 голосов
/ 25 сентября 2018

Вы можете добавить новый стиль, который наследует базовый стиль метки LabelTitle это должно быть что-то вроде этого

СТИЛЬ XAML

<Style x:Key="EnableSTypeLabel" BasedOn="{StaticResource LabelTitle}" TargetType="Label">
    <Style.Triggers>
        <DataTrigger Binding="{Binding ElementName=Combo_FType, Path=SelectedIndex}" Value="3">
            <Setter Property="IsEnabled" Value="True" />
        </DataTrigger>
    </Style.Triggers>
</Style>

XAML

<Label Style="{StaticResource EnableSTypeLabel}" Content="S" x:Name="Label_SType" Margin="25.087,3.1,-94.145,29.092" d:LayoutOverrides="Width, Height" Grid.Row="1"  />
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...