Is there a way I can add custom property to RadWatermarkTextBox? For example adding isRequired property and use it in the control template.
Thank you.
1 Answer, 1 is accepted
0
Martin Ivanov
Telerik team
answered on 09 Oct 2020, 06:01 AM
Hello Gerardo,
To achieve your requirement, you can create a custom class that derives from RadWatermarkTextBox and add the custom property there. After this, you can extract the default ControlTemplate of RadWatermarkTextBox and use the new property in the template.
For example:
publicclassCustomWatermarkTextBox : RadWatermarkTextBox
{
publicbool IsRequired
{
get { return (bool)GetValue(IsRequiredProperty); }
set { SetValue(IsRequiredProperty, value); }
}
publicstaticreadonly DependencyProperty IsRequiredProperty =
DependencyProperty.Register(
"IsRequired",
typeof(bool),
typeof(CustomWatermarkTextBox), new PropertyMetadata(false));
}
<Window.Resources><ControlTemplatex:Key="CustomWatermarkTextBoxTemplate"TargetType="local:CustomWatermarkTextBox"><!-- some elements here --><!-- an element in the template that uses the new property --><CheckBoxIsChecked="{TemplateBinding IsRequired}" /><!-- some other elements here --></ControlTemplate><StyleTargetType="local:CustomWatermarkTextBox"><SetterProperty="Template"Value="{StaticResource CustomWatermarkTextBoxTemplate}" /></Style></Window.Resources>
Regards,
Martin Ivanov
Progress Telerik
Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive, special prizes, and more, for FREE?! Register now for DevReach 2.0(20).