对于一个我一直在做的项目,我正在将一些自定义控件从WPF平台移植到UWP。在WPF方面,它是这样实现的:
public static readonly DependencyProperty MaxLengthProperty = DependencyProperty.Register("MaxLength", typeof(int), typeof(HexBox), new PropertyMetadata(MaxLength_PropertyChanged));
public int MaxLength
{
get { return (int)GetValue(MaxLengthProperty); }
set { SetValue(MaxLengthProperty, value); }
}
private static void MaxLength_PropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
HexBox hexControl = (HexBox)d;
hexControl.txtValue.MaxLength = (int)e.NewValue;
}在没有参数的情况下使用MaxLength_PropertyChanged。当我试图在UWP中做同样的事情时,我会收到以下信息:
参数1:无法从“方法组”转换为“对象”
我知道这与不传递参数或将它们作为()方法调用有关。但在WPF中,这种行为是隐式的。
有人有主意吗?
发布于 2017-05-22 13:06:56
试试这个:
public static readonly DependencyProperty MaxLengthProperty = DependencyProperty.Register(
"MaxLength",
typeof(int),
typeof(HexBox),
new PropertyMetadata(0, new PropertyChangedCallback(MaxLength_PropertyChanged))
);
private static void MaxLength_PropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
HexBox hexControl = d as HexBox;
hexControl.txtValue.MaxLength = (int)e.NewValue;
}https://stackoverflow.com/questions/44113491
复制相似问题