Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to use default style with datatriggers?

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>

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading