我很难找到如何在 UWP 中注册 RoutedEventHandler。我正在尝试编写具有类似于 ContentDialog 的事件属性的模板控件:
PrimaryButtonClick="ClickEvent"
其中 ClickEvent 是在 cs 文件中定义的。我只是掌握了模板的窍门,但我相信我想做一些看起来像这样的事情:
<Button Content="{TemplateBinding PrimaryButtonText}" Click="{TemplateBinding PrimaryButtonClick}"/>
目前,我能找到的只是对此类代码的 WPF 版本的引用:
public static readonly RoutedEvent ValueChangedEvent =
EventManager.RegisterRoutedEvent("ValueChanged",
RoutingStrategy.Direct, typeof(RoutedPropertyChangedEventHandler<double>),
typeof(NumericBox));
public event RoutedPropertyChangedEventHandler<double> ValueChanged
{
add { AddHandler(ValueChangedEvent, value); }
remove { RemoveHandler(ValueChangedEvent, value); }
}
private void OnValueChanged(double oldValue, double newValue)
{
RoutedPropertyChangedEventArgs<double> args =
new RoutedPropertyChangedEventArgs<double>(oldValue, newValue);
args.RoutedEvent = NumericBox.ValueChangedEvent;
RaiseEvent(args);
}
但是当然类型已经改变了。有人可以指出我正确的方向吗?