尝试在 Xamarin Forms MVVM 模式项目中使用 Xamarin 社区工具包弹出窗口,目标平台 IOS 和 Android。弹出窗口正在出现,但是我无法绑定以显示来自 viewmodel 的 PopUpMessage 字符串。这是我的代码。
XAML:
<xct:Popup.BindingContext>
<viewmodels:ProviderApplicationViewModel />
</xct:Popup.BindingContext>
<StackLayout Style="{StaticResource PopupLayout}">
<Label Style="{StaticResource Title}"
Text="Application Status" />
<BoxView Style="{StaticResource Divider}" />
<Label Style="{StaticResource Content}"
Text="{Binding PopUpMessage}"
TextColor="Black"/>
<Button Text="OKAY"
Style="{StaticResource ConfirmButton}"
Clicked="Button_Clicked" />
</StackLayout>
代码背后:
public partial class ProviderApplicationPopup : Popup
{
public ProviderApplicationPopup()
{
InitializeComponent();
}
void Button_Clicked(object sender, System.EventArgs e) => Dismiss(null);
}
视图模型:
private string popupmessage;
public string PopUpMessage
{
set { SetProperty(ref popupmessage, value); }
get { return popupmessage; }
}
ViewModel 弹出导航:
if (response == "True")
{
PopUpMessage = "Your application has been submitted!";
Navigation.ShowPopup(new ProviderApplicationPopup());
IsBusy = false;
return;
}