我在将值绑定到ContentView我所做的自定义时遇到问题。
我的MainPage用途CustomFrameView是ContentView.
我的CustomFrameView有一根绳子BindableProperty。当我手动输入字符串时,这可以正常工作,但当我尝试使用绑定时,这会失败。我确信绑定应该有效,因为它在Label.
任何人都知道为什么它不起作用?
主页.xaml
<StackLayout>
<!-- DOES work -->
<Label Text="{Binding Name}"/>
<!-- DOES work-->
<controls:CustomFrameView TestName="Test456"/>
<!-- DOES NOT work-->
<controls:CustomFrameView TestName="{Binding Name}"/>
</StackLayout>
Run Code Online (Sandbox Code Playgroud)
MainPage.xaml.cs
<StackLayout>
<!-- DOES work -->
<Label Text="{Binding Name}"/>
<!-- DOES work-->
<controls:CustomFrameView TestName="Test456"/>
<!-- DOES NOT work-->
<controls:CustomFrameView TestName="{Binding Name}"/>
</StackLayout>
Run Code Online (Sandbox Code Playgroud)
MainPageViewModel.cs
public MainPage()
{
InitializeComponent();
BindingContext = new MainPageViewModel();
}
Run Code Online (Sandbox Code Playgroud)
CustomFrameView.xaml.cs
public partial class MainPageViewModel : ObservableObject
{ …Run Code Online (Sandbox Code Playgroud)