Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

How do you set the default value of a Thickness BindableProperty?

$
0
0

I am attempting to create a BindableProperty for a control, but it doesn't appear to be setting the default value correctly. Specifically I am trying to set the padding of a Frame from a BindableProperty. Now if this propery is assigned a value in the XAML where I use the ContentView it works great. It is only if I don't specify a value where it doesn't work. Here is the code for the property:

Xaml for the property

<Frame x:Name="borderFrame" >
    <Frame x:Name="backgroundFrame" >
        <Label 
            x:Name="textLabel" 
            HorizontalOptions="Center"
            VerticalOptions="Center"
            />
    </Frame>
</Frame>

BindableProperty for the frame padding

public static BindableProperty BorderWidthProperty = BindableProperty.Create(
            nameof(BorderWidth),
            typeof(Thickness),
            typeof(TextBox),
            new Thickness(3),
            BindingMode.TwoWay,
            propertyChanged: (BindableObject bindable, Object oldVlaue, Object newValue) =>
            {
                TextBox textBox = (TextBox)bindable;
                textBox.borderFrame.Padding = (Thickness)newValue;
            });

Now if I make a textbox like this

<local:Textbox 
        Text="Hello World."
        BorderWidth="2"
/>

then I see a padding of 2 in the border Frame, but if I omit that like so

<local:TextBox
        Text="Hello World."
/>

then I would expect it to revert to the default - a thickness of 3, but instead the padding is 20, the default padding for a Frame.
It would appear that I am not setting the default correctly. How should I set the default?


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>