maui-bindableproperty-generator
maui-bindableproperty-generator copied to clipboard
Binding to label
I am not sure what I am doing wrong here - I am trying to bind the text value of a label as part of my custom control.
My control code behind looks like this: using Maui.BindableProperty.Generator.Core; namespace TestCustomControls.Controls;
public partial class HeaderControl : VerticalStackLayout { [AutoBindable()] private readonly string? _firstName;
[AutoBindable(DefaultBindingMode = nameof(BindingMode.OneWayToSource))]
private readonly string? _message;
public HeaderControl()
{
InitializeComponent();
}
}
My control xaml looks like this:
<VerticalStackLayout x:Class="TestCustomControls.Controls.HeaderControl" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
<Label Text="First Name" />
<Entry Text="{Binding Source={x:Reference this}, Path=FirstName}" />
<Label
FontAttributes="Bold"
FontSize="Header"
Text="{Binding Source={x:Reference this}, Path=Message}"
TextColor="Black" />
My test solution can be found at https://github.com/420tech/TestCustomControls. I can't get the label to render.
I think the bindingmodes are wrong: FirstName should be OneWayToSource and Message should be OneWay.