【发布时间】:2016-10-12 02:23:08
【问题描述】:
我做了一个非常简单的 Yes/No RadioBox 控件。
在它后面的代码中,我有以下BindableProperty:
public static readonly BindableProperty SelectedValueProperty = BindableProperty.Create(
"SelectedValue",
typeof(int),
typeof(YesNoView),
0,
BindingMode.TwoWay);
它的属性:
public int SelectedValue
{
get { return (int) GetValue(SelectedValueProperty); }
set { SetValue(SelectedValueProperty, value); }
}
此属性使用如下方式绑定在 ContentView-XAML 中:
<DataTrigger Binding="{Binding SelectedValue}" Value="0" TargetType="Image">
<Setter Property="Source" Value="radiobutton_checked.png" />
</DataTrigger>
每当我在某个页面中使用我的 ContentView 并将 SelectedValue 设置为一个常量值时,一切正常!
但是,当我使用{Binding SomeValue} 而不是常量值时,其中SomeValue 是我正在使用 ContentView 的页面上的一个属性(带有通知),它只会拒绝执行任何操作。每当我将SomeValue 设置为某个值时,它永远不会到达 ContentView,这让我发疯了,为什么它不起作用。
即使我调整 BindableProperty 以同时指定 propertyChanged 事件,它也不会触发,除非我恢复为 Xaml 中的常量值,而不是绑定。
任何人都可以解释为什么会发生这种情况并且没有按我的预期工作吗?
编辑:我应该在页面和视图中添加 BindingContext 设置为此。
【问题讨论】:
标签: c# xaml xamarin xamarin.forms