UWPa new way DataBinding, Compiled Bindingusing the markup extension {x:Bind}when I found this new feature, I have found that we can bind an event to a method!
Example:
Xaml:
<Grid>
<Button Click="{x:Bind Run}" Content="{x:Bind ButtonText}"></Button>
</Grid>
Code for:
private string _buttonText;
public string ButtonText
{
get { return _buttonText; }
set
{
_buttonText = value;
OnPropertyChanged();
}
}
public MainPage()
{
this.InitializeComponent();
ButtonText = "Click !";
}
public async void Run()
{
await new MessageDialog("Yeah the binding worked !!").ShowAsync();
}
Result:

And since the {x: Bind} bindings are evaluated at runtime, and the compiler generates some files that represent this binding, so I went there to find out what is happening, therefore, in the MainPage.g.cs file (MainPage is the xaml file) . I found this:
public void Connect(int connectionId, global::System.Object target)
{
switch(connectionId)
{
case 2:
this.obj2 = (global::Windows.UI.Xaml.Controls.Button)target;
((global::Windows.UI.Xaml.Controls.Button)target).Click += (global::System.Object param0, global::Windows.UI.Xaml.RoutedEventArgs param1) =>
{
this.dataRoot.Run();
};
break;
default:
break;
}
}
The compiler seems to know that this is a valid binding, in addition, it creates an appropriate event handler and calls the corresponding method inside.
! ?? , . {x: Bind} , , non dependency , , ?