WPF RadWatermarkTextBox - Setting Margin using a Style resource not working

0 Answers 42 Views
WatermarkTextBox
Wizard6650
Top achievements
Rank 1
Wizard6650 asked on 05 Sep 2023, 09:38 AM

I am trying to apply the same `Margin` style to a lot of `RadWatermarkTextBox` controls by defining the `Margin` as a Style resource:

<Window.Resources>
    <Style TargetType="{x:Type telerik:RadWatermarkTextBox}">
        <Setter Property="Margin">
            <Setter.Value>
                <Thickness Bottom="{x:Static controls:Measurements.UnrelatedDistance}" />
            </Setter.Value>
        </Setter>
    </Style>
</Window.Resources>

Using the Style above makes the control look different compared to explicitly setting the `Margin` property for each control like below:

<telerik:RadWatermarkTextBox Text="Hello world">
    <telerik:RadWatermarkTextBox.Margin>
        <Thickness Bottom="{x:Static controls:Measurements.UnrelatedDistance}" />
    </telerik:RadWatermarkTextBox.Margin>
</telerik:RadWatermarkTextBox>

I am wondering what's the reason for this difference and how to use a Style resource to the make the control look like the way it does when explicitly setting the `Margin` property within the control.

Thank you.

Martin Ivanov
Telerik team
commented on 06 Sep 2023, 08:05 AM

What do you mean by saying that the control look different? Do you mean that the Margin doesn't work when setting it through the Style, or the visualization of the control is different?

Note that, if you use the Telerik's NoXaml assemblies, you will need also to set the BasedOn property on the Style object.

<Style TargetType="{x:Type telerik:RadWatermarkTextBox}" BasedOn="{StaticResource RadWatermarkTextBoxStyle}">

No answers yet. Maybe you can help?

Tags
WatermarkTextBox
Asked by
Wizard6650
Top achievements
Rank 1
Share this question
or