我创建了一个控件,它有一个可绑定的属性,但是当我尝试设置它的值时,它没有设置,当我检查它的setter时,它在调试时没有被命中,不确定我做错了什么。
public decimal MetricValue
{
get => (decimal)GetValue(MetricValueProperty);
set => SetValue(MetricValueProperty, value);
}
public static readonly BindableProperty MetricValueProperty =
BindableProperty.Create(
propertyName: nameof(MetricValue),
returnType: typeof(decimal),
declaringType: typeof(HeightSelection),
defaultBindingMode: BindingMode.TwoWay,
propertyChanged: MetricValuePropertyChanged);
我还有一个属性已更改,它没有被提升。
<controls:customControl
CurrentSystemOfMeasure="{Binding CurrentSystemOfMeasure}"
MetricValue="{Binding CurrentHeight}"
TextAlignment="Start"
OnHeightSelectedCommand="{Binding HeightSelectionCommand}"
IsValid="True" />
任何意见都是有帮助的,
2条答案
按热度按时间41ik7eoe1#
在xaml视图中设置上下文了吗?
说到这里我道:
ContentView需要有一个x:name来设置属性IsVisible中的上下文。在您的情况下,需要在标签的Text属性中设置上下文以显示十进制值
我已设置上下文,使其引用我的自定义视图selphiDetailPhotosView
最后,在ContentPage中调用自定义控件并与ViewModel绑定
<customControl:SelphiDetailPhotosView CancelButtonVisible="{Binding CanCancel}"/>
3okqufwl2#
我已经复制了你的场景,这对我很有效。
CodeBehind自订控件
自定义控件XAML
调用自定义控件的ContenPage
检视模型
Decimal Binding Result可能您在创建可绑定属性时忘记了默认值