Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
<Style TargetType="{x:Type inf:MyObject}">
<Setter Property="Header" Value="{Binding Header}" />
</Style>
How can I create separate styles constrained on the ObjectType enum field? I.E. have a separate style for a MyObject with an ObjType set to Type1 vs Type2?
My fields do implement INotifyPropertyChanged, this is just some brief sample code
Thanks
<Style TargetType="{x:Type inf:MyObject}">
<Setter Property="Header" Value="{Binding Header}" />
<Style.Triggers>
<DataTrigger Binding="{Binding ObjType}" Value="Type1">
<!-- A bunch of setters -->
</DataTrigger>
<DataTrigger Binding="{Binding ObjType}" Value="Type2">
<!-- Another bunch of setters -->
</DataTrigger>
</Style.Triggers>
</Style>
Separation is probably not possible.
Well, you can create separate styles but you would need to apply them manually using the ResourceKey:
<Style x:Key="Type1Style" TargetType="{x:Type inf:MyObject}"
BasedOn="{StaticResource {x:Type inf:MyObject}}">
<!-- Setters for type1 -->
</Style>
<Style x:Key="Type2Style" TargetType="{x:Type inf:MyObject}"
BasedOn="{StaticResource {x:Type inf:MyObject}}">
<!-- Setters for type2 -->
</Style>
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.