小编Jay*_*one的帖子

绑定不适用于自定义 BindableProperty

我在将值绑定到ContentView我所做的自定义时遇到问题。

我的MainPage用途CustomFrameViewContentView.

我的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)

c# xaml mvvm maui .net-maui

5
推荐指数
1
解决办法
1520
查看次数

标签 统计

.net-maui ×1

c# ×1

maui ×1

mvvm ×1

xaml ×1