Attempting to utilize Xamarin Community Toolkit Popups in Xamarin Forms MVVM pattern project, target platforms IOS & Android. Popups are appearing, however I cannot bind to display my PopUpMessage string from viewmodel. Here is my code.
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>
Code Behind:
public partial class ProviderApplicationPopup : Popup
{
public ProviderApplicationPopup()
{
InitializeComponent();
}
void Button_Clicked(object sender, System.EventArgs e) => Dismiss(null);
}
ViewModel:
private string popupmessage;
public string PopUpMessage
{
set { SetProperty(ref popupmessage, value); }
get { return popupmessage; }
}
ViewModel Popup Navigation:
if (response == "True")
{
PopUpMessage = "Your application has been submitted!";
Navigation.ShowPopup(new ProviderApplicationPopup());
IsBusy = false;
return;
}
I can't tell until I've seen rest of the code though I think the issue is how you are instantiating your
ProviderApplicationPopup.First your are setting
PopupMessagevalue then you instantiateProviderApplicationPopupbut then probablyProviderApplicationPopupis also instantiate new ViewModel with nullPopupMessagevalue.So you could pass string directly when instantiating
ProviderApplicationPopuplikenew ProviderApplicationPopup("Your application has been submitted!")then set the value in constructorP.S: Or you can also instantiate ViewModel first then pass that to
ProviderApplicationPopupand then bind it.Edit: