无法从方法组转换为对象移植 WFP => UWP
cannot convert from method group to object porting WFP => UWP
对于我一直从事的项目,我正在将一些自定义控件从 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 中做同样的事情时,我收到以下消息:
Argument 1: cannot convert from 'method group' to 'object'
我知道这与不传递参数或使用 () 作为方法调用它们有关。但在 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;
}
对于我一直从事的项目,我正在将一些自定义控件从 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 中做同样的事情时,我收到以下消息:
Argument 1: cannot convert from 'method group' to 'object'
我知道这与不传递参数或使用 () 作为方法调用它们有关。但在 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;
}