I'm using the Telerik UI for WPF framework. This includes the RadMaskedTextInput
control and I struggle to set the ClearButtonStyle
. How can I assign a style to it in code-behind?
Asked
Active
Viewed 223 times
0

thatguy
- 21,059
- 6
- 30
- 40

marek heczko
- 15
- 6
-
Does this answer your question? [How to set the style programmatically](https://stackoverflow.com/questions/3199424/how-to-set-the-style-programmatically) – Bizhan Jul 10 '20 at 09:44
1 Answers
1
Assign a name to your RadMaskedTextInput
control in XAML.
<telerik:RadMaskedTextInput x:Name="MaskedTextInput"/>
If your style is defined with a in XAML, use FindResouce
<Style x:Key="MaskedTextInputStyle" TargetType="{x:Type telerik:RadButton}">
<!-- Your style definitions -->
</Style>
var clearButtonStyle = (Style) FindResource("YourResourceKey");
You can also create the style in code-behind. Add e.g. setters and triggers to the corresponding collections.
var clearButtonStyle = new Style(typeof(RadButton));
Then in code-behind - the *.xaml.cs
file - assign the style.
MaskedTextInput.ClearButtonStyle = clearButtonStyle;

thatguy
- 21,059
- 6
- 30
- 40
-
-
1Of course, add a `Setter` that sets the `Content` property to simply plain text `X` or use a `RadGlyph`. You can read more on that [here](https://docs.telerik.com/devtools/wpf/styling-and-appearance/glyphs/common-styles-appearance-glyphs-radglyph). – thatguy Jul 10 '20 at 11:36