Do other components have a Template argument?
I am tried to set Template to TextBox but I can't find this argument.
when I try to write it, it still not returning a result.
I am searching more methods to avoid code duplication, like Style and Template.
I'm trying to set some text inside some box that with specific design.
Also, will be thankful to get some explanation how to fix this code and use boxes more correctly.
This my attempt about the "grid" element to make it as a template
Thanks for help.
when I try to write it, it still not returning a result.
I am searching more methods to avoid code duplication, like Style and Template.
I'm trying to set some text inside some box that with specific design.
Also, will be thankful to get some explanation how to fix this code and use boxes more correctly.
This my attempt about the "grid" element to make it as a template
Thanks for help.
Re: Do other components have a Template argument?
Several things can be done to avoid duplication.
First of all, in your example, BasedOn is a property that can be assigned to Styles, but not to Control template
For your usecase, maybe a good approach would be to pack your set of data (text + visibility) inside a Type and then define a DataTemplate for it.
This then allows your to simply bind this data class and have this template replicated to show the data appropriatedly, you can set this datatemplate in a style using the ContentTemplate property.
First of all, in your example, BasedOn is a property that can be assigned to Styles, but not to Control template
Code: Select all
<Style TargetType="{x:Type Grid}">
<!-- This need to exist somewhere -->
</Style>
<Style x:Key="FooBar.Grid" TargetType="{x:Type Grid}" BasedOn="{StaticResource {x:Type Grid}}">
<!-- Write your overrides here -->
</Style>
Code: Select all
<DataTemplate x:Key="yourDataTemplate" DataType="{x:Type SomeDataClass}">
<Border Visibility="{Binding TheVisibility}">
<TextBlock Text="{Binding PropertyText}" Foreground="{Binding ExampleImportanceColor}"/>
</Border>
</DataTemplate>
-
sfernandez
Site Admin
- Posts: 3008
- Joined:
Re: Do other components have a Template argument?
All FrameworkElements expose a Style property which will allow you to define property setters (and even triggers) to avoid duplication.
Then, all Controls expose also a Template property (of type ControlTemplate) where you can define the appearance of that control and how it reacts to the changes in the control properties (for example, in a Button template you can change the background color of a Border included in the template depending on the values of IsMouseOver or IsPressed properties).
Please explore the hierarchies in the documentation to know all the Control classes available by default.
Then, all Controls expose also a Template property (of type ControlTemplate) where you can define the appearance of that control and how it reacts to the changes in the control properties (for example, in a Button template you can change the background color of a Border included in the template depending on the values of IsMouseOver or IsPressed properties).
Please explore the hierarchies in the documentation to know all the Control classes available by default.
Who is online
Users browsing this forum: Bing [Bot], Semrush [Bot] and 6 guests