Hello,
Try to check Source={x:Reference CustomView}
, please make sure CustomView
is the name of your ContentView
( CustomViewControl
), refer to the following code:
CustomControl XAML
<?xml version="1.0" encoding="utf-8" ?>
<ContentView ......
x:Name="MyCustomView">// key point
<StackLayout>
<Label
Margin="0,-5,0,0"
Padding="10,0"
FontAttributes="Italic"
HorizontalOptions="EndAndExpand"
Text="{Binding IsBusy, Source={x:Reference MyCustomView}, StringFormat='The value is {0}'}"
/>
<Button IsVisible="{Binding IsBusy, Source={x:Reference MyCustomView}}" Text="New" />
<Button
HorizontalOptions="Center"
Clicked="Button_Clicked"
Text="Change" />
</StackLayout>
</ContentView>
Click button to change the Value of IsBusy
private void Button_Clicked(object sender, EventArgs e)
{
this.IsBusy = !this.IsBusy;
}
MainPage
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="CustomViewMAUIDemo.MainPage"
xmlns:local ="clr-namespace:CustomViewMAUIDemo">
<local:CustomView IsBusy ="True" >
</local:CustomView>
</ContentPage>
Best Regards,
Wenyan Zhang
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.