A data binding architecture is important feature for client side MVC. In XAML until windows 8.1, it had been implemented by binding path mechanism only. From windows 10, a new compile time binding mechanism by “x:Bind” keyword of x name space(http://schemas.microsoft.com/winfx/2006/xaml) has offering. br>
x:Bind sample provided by Microsoft explains that it is fast rendering processing to display, and a bind error given on compile time may make development to more productive.
This article constructed with three sections. As first, XAML description part, and second part is about data, the last is note of xBind.
>>Sample solution for Visual Studio 2017
・XAML
It’s most important aspect for creating XAML is that it should be written to define semantic construct same as a contents which is displayed. For more ease maintenance, data context for XAML must be created as possible as simple.
In case of Initial page of an app, A data context of the page structed by menu and first content must be structed a data context of menu list and first content respectively. Thus when item of menu list is changed, first page contents replaced with contents of item of menu list.
To omit about page contents in this article, describes just menu and application title. In aspect of contents, every contents has page title section and lead paragraph, contents body. It is created by general data context as base data context. There is described at follows Data section.
If needs the copy, use the GitHub Gist is below.
‘x:Bind’ syntax binding mode is one time binding as default. In abobe figure, there is three bindings which mode is one time binding. First one is bind to the property of data context of the XAML, the last one is bind to the property of data context of page contents which defined by menu item selection.
・Data
The second binding of above figure binds to Menu property of the XAML. The property is List
public class MenuItemContext br>
{ br>
public string PageTitle { get; set; } br>
public string Lead { get; set; } br>
public ContentTypes CurrentType { get; set; } br>
} br>
public class ProfileContent : MenuItemContext br>
{ br>
public ProfileContent() br>
{ br>
CurrentType = ContentTypes.Profile; br>
Lead = “Aquiring from SNS or idenity provider”; br>
PageTitle = “Create Profile”; br>
} br>
… br>
} br>
public enum ContentTypes : int br>
{ br>
Profile = 0, br>
… br>
Other br>
} br>
public class MainVM br>
{ br>
public MainVM() br>
{ br>
Menu = new List<MenuItemContext>(); br>
Current = new ProfileContent(); br>
Menu.Add(Current); br>
AppTitle = “My App”; br>
} br>
public List<MenuItemContext> Menu { get; set; } br>
public string AppTitle { get; set; } br>
} br>
The Menu property is List
With this structure, can develop other pages by extending MenuItemContext type.
・Note
1. Default binding mode is OneTime.
2. Needs solve every types in XAML.
3. Can bind event. But XAML must be described as possible as simple. if page contents is not need change an event dynamically, it should not be used event binding to data context, it should be defined by code behind.
For additional, data context of XAML is ViewModel property of code behind.
public sealed partial class MainPage : Page br>
{ br>
public MainVM ViewModel { get; set; } br>
public MainPage() br>
{ br>
this.InitializeComponent(); br>
ViewModel = new MainVM(); br>
} br>
private void MenuList_SelectionChanged(object sender, SelectionChangedEventArgs e) br>
{ br>
ListBox menuListBox = sender as ListBox; br>
… br>
} br>
} br>
No responses yet