WPF RadWatermarkTextBox - Setting Margin using a Style resource not working

0 Answers 79 Views
WatermarkTextBox
Wizard6650
Top achievements
Rank 1
Iron
Iron
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}">

Wizard6650
Top achievements
Rank 1
Iron
Iron
commented on 22 Mar 2024, 03:32 AM

Thank you. Using the BasedOn property solved the issue.

No answers yet. Maybe you can help?

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