Assume we have a button declared in XML :
<button x:Class="A" Content="click me" Name="button" />
And in the accompanying class A we have
public partial class A {
BHandler b = new BHandler();
}
and the class BHandler consits of:
public class BHandler {
clickHandler(object sender, RoutedEventArgs){
Console.WriteLine("button clicked!");
}
}
My question is: Is it possible to register the event h开发者_开发知识库andler in b directly to the button, by something like:
Click="b.clickHandler"
rather than having the event handler in the partial C# class that accompanies the AXML?
You can for example use some kind of MVVM frameworks as for example Caliburn Micro. With this one you can just have the function implemented in the view model and have it bound autoamtically by naming convention.
精彩评论