Home > Blockchain >  How to use default style with datatriggers?
How to use default style with datatriggers?

Time:03-19

I have default styles set from MaterialDesignInXaml and when I try to add a datatrigger to the control it does not use that same style.

How do I still use the default style while having datatriggers?

<TextBox Margin="10" VerticalAlignment="Bottom" Padding="5" materialDesign:HintAssist.Hint="Search">
       <TextBox.Style>
              <Style BasedOn="{StaticResource MaterialDesignOutlinedTextBox}"> <!--Not Allowed to do this -->
                  <Setter Property="TextBox.Visibility" Value="Collapsed"></Setter>
                  <Style.Triggers>
                       <DataTrigger Binding="{Binding ElementName=SearchStyle, Path=SelectedItem.Tag}" Value="Search">
                            <Setter Property="Label.Visibility" Value="Visible"></Setter>
                       </DataTrigger>
                  </Style.Triggers>
              </Style>                       
        </TextBox.Style>
</TextBox>

CodePudding user response:

You have to specify the exact TargetType for the Style that matches the base style.

[...] if you create a style with a TargetType property and base it on another style that also defines a TargetType property, the target type of the derived style must be the same as or be derived from the target type of the base style.

<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource MaterialDesignOutlinedTextBox}">

In the source code, the MaterialDesignOutlinedTextBox style has a TextBox target type.

  • Related