【发布时间】:2020-02-27 06:30:23
【问题描述】:
尝试将视图的属性绑定到在 ViewModel 上创建的任何源时出现问题,例如标签的 Text 属性test(代码如下)不起作用,但我制作的 Button 的 Text 属性绑定到发送到此视图模型的另一个对象并正常工作。我只是想了解为什么绑定无法正常工作。 这是代码。
XAML.cs
public PopupView(Func<bool> metodo, Tarefa tarefa)
{
BindingContext = new ViewModels.Popups.PopupViewModel(metodo, tarefa);
InitializeComponent();
}
XAML
<pages:PopupPage
xmlns:animations="clr-namespace:Rg.Plugins.Popup.Animations;assembly=Rg.Plugins.Popup"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="Taskinho.Views.Popups.PopupView"
xmlns:pages="clr-namespace:Rg.Plugins.Popup.Pages;assembly=Rg.Plugins.Popup">
<StackLayout>
<Label HorizontalOptions="Center" Text="{Binding test}" />
<Button Text="{Binding tarefa.TarefaTitulo}" Command="{Binding Confirmar}" />
</StackLayout>
</pages:PopupPage>
视图模型
//Property
private Tarefa _Tarefa;
public Tarefa tarefa
{
get { return _Tarefa; }
set { _Tarefa = value;
NotifyPropertyChanged("Tarefa");
}
}
//another property
public string test = "Test Name";
//Constructor
public PopupViewModel(Func<bool> metodoParam, Tarefa TarefaParam)
{
this.tarefa = new Tarefa();
ExecutarCommand = new Command(ExecutarAction);
}
//The binded Command(Not finded by the binding)
public Command ExecutarCommand
{
get;
set;
}
//Action of Command
void ExecutarAction()
{
//do something
}
我尝试在 Button 绑定上使用 Path="" 和 Source="" 但我不知道如何用于这种情况。
谢谢
【问题讨论】:
-
如果我的回复解决了您的问题,请记得将我的回复标记为答案,谢谢。
标签: xamarin mvvm xamarin.forms popup