gpt4 book ai didi

c# - 使用 x :Bind with MvvmCross

转载 作者:太空宇宙 更新时间:2023-11-03 23:24:12 24 4
gpt4 key购买 nike

在尝试在 MvvmCross 中编写 TipCalc 示例时,我尝试使用 x:Bind 而不是常规绑定(bind)(在通用应用程序编程中)

我的代码是这样的:

public sealed partial class TipView 
{
public new TipViewModel ViewModel
{
get { return (TipViewModel)base.ViewModel; }
set { base.ViewModel = value; }
}

public TipView()
{
this.InitializeComponent();
}
}

我的 xaml 看起来像这样:

<Grid x:Name="ContentPanel" 
Margin="12,0,12,0"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
>
<StackPanel>
<TextBlock
Text="SubTotal"
/>
<TextBox
Text="{x:Bind ViewModel.SubTotal, Mode=TwoWay}"
/>
.
.
.

编译时出现以下错误:

Microsoft.Windows.UI.Xaml.Common.targets(350,5): Xaml Internal Error error WMC9999: Unable to cast object of type 'Microsoft.MetadataReader.MetadataOnlyPropertyInfo' to type 'System.Reflection.MethodInfo'.

我正在使用 3.5.1 版本的 MvvmCross 库(最后一个稳定版本)

这是一个错误吗?或者我在这里缺少什么?

最佳答案

我在我的代码中使用了以下语法

public TipViewModel Vm => (TipViewModel) ViewModel;

绑定(bind)将是

Text="{x:Bind Vm.SubTotal, Mode=TwoWay}"

不确定为什么会收到错误,您的 View 确实继承自 MvxWindowsPage

关于c# - 使用 x :Bind with MvvmCross,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34357545/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com