我正在使用WPF框架的Telerik UI。这包括RadMaskedTextInput
控制和我努力设置ClearButtonStyle
。如何在代码隐藏中为其指定样式?
在XAML中为RadMaskedTextInput
控件指定一个名称。
<telerik:RadMaskedTextInput x:Name="MaskedTextInput"/>
如果您的样式是用XAML中的定义的,请使用FindResouce
<Style x:Key="MaskedTextInputStyle" TargetType="{x:Type telerik:RadButton}">
<!-- Your style definitions -->
</Style>
var clearButtonStyle = (Style) FindResource("YourResourceKey");
您也可以在代码隐藏中创建样式。将例如setter和触发器添加到相应的集合中。
var clearButtonStyle = new Style(typeof(RadButton));
然后在代码后面的*.xaml.cs
文件中指定样式。
MaskedTextInput.ClearButtonStyle = clearButtonStyle;