'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>
Solution 1:[1]
You have to specify the exact TargetType for the Style that matches the base style.
[...] if you create a style with a
TargetTypeproperty and base it on another style that also defines aTargetTypeproperty, 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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | thatguy |
