I am currently working on a UWP application and I would like to use the compiled binding system.
I have a base that extends the Windows.UI.Xaml.Controls.Page
that contains a property ViewModel
.
Here the base class of the ViewModel
Property :
public class BaseViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void RaiseOnPropertyChanged([CallerMemberName] string propertyName = "")
{
OnPropertyChanged(propertyName);
}
public void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
And here my base page :
public abstract class BasePage : Page
{
public BaseViewModel ViewModel { get; set; }
}
The pages of my app extends the BasePage
and contain a nester (inner) class that extends the BaseViewModel
class. Here a sample code :
public sealed partial class MyPage : BasePage
{
public sealed class MyViewModel : BaseViewModel
{
public string Title
{
get
{
return "Test";
}
}
}
public MyPage()
{
InitializeComponent();
ViewModel = MyViewModel();
}
}
Now, I would like to bind the property Title
of the MyViewModel
class to my UI. According to this article and this one, something like that should work :
<TextBlock
Text="{x:Bind ViewModel.(namespace:MyPage+MyViewModel.Title)}"
/>
Unfortunately, I cannot compile. I have several errors on the generated file MyPage.g.cs
due to the "+" char. Do you know if the binding on a nested (inner) class is supported in UWP application ? Perhaps it is supported only on WPF app ? :(
Thank you for your help !