无法从方法组转换为对象移植WFP => UWP
问题描述:
对于我一直在努力的项目,我将一些自定义控件从WPF平台移植到UWP。 在WPF侧它是作为这样实现的:无法从方法组转换为对象移植WFP => UWP
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中这种行为是隐含的。
任何人有想法?
答
试试这个:
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;
}
这工作,感谢了一堆,原来你需要在UWP很多更详细。 –