Hello,
I test your code, I get the same result. this issue should be bind issue. You can try to use this XAML data binding diagnostics - Visual Studio (Windows) tools in Visual Studio to detect and resolve data binding errors in XAML projects.
Here is a solution about your issue, you can refer to it.
If you want to bind the BindableProperty
to your controls of contentView layout, you do not need to bind it in the XAML, you can add the x:Name
, set the binding value in the background code directly with propertyChanged property and achieve propertyChanged method.
Firstly, add the x:name
for your controls in the XAML like the following code.
<ContentView.Content>
<Grid>
<BoxView
x:Name="MyBoxView"
HeightRequest="6"
WidthRequest="6"
CornerRadius="50"
VerticalOptions="Start"
/>
<Button
x:Name="MyButton"
FontSize="20"
BackgroundColor="Transparent"
FontFamily="Fontello"
/>
<Label
x:Name="MyLabel"
FontSize="12"
VerticalOptions="EndAndExpand" />
</Grid>
</ContentView.Content>
Second, you can add propertyChanged:
method for all the BindableProperties and set them.
For example, I want to set MyBoxView.BackgroundColor
, you can refer to the following code.
public static readonly BindableProperty DotColorProperty = BindableProperty.Create(
nameof(DotColor),
typeof(Color),
typeof(TabBarButton),
null,
BindingMode.OneWay,
propertyChanged:DotColorChanged);
public Color DotColor
{
get => (Color)GetValue(DotColorProperty);
set => SetValue(DotColorProperty, value);
}
static void DotColorChanged(BindableObject bindable, object oldValue, object newValue)
{
TabBarButton control = bindable as TabBarButton;
control.MyBoxView.BackgroundColor = newValue as Color; // it is same that you set Color="{Binding Source={x:Reference ButtonTabBar}, Path=DotColor, Mode=OneWay}"
}
You have a BindableProperty with ICommand
. It is different, you can set the command with control.MyButton.Command=(ICommand)newValue;
in the TabBarCommandChanged
method.
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.