我做了一个非常简单的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设置为此。
发布于 2016-10-12 02:46:15
我花了4个小时才弄明白.
不要在您的BindingContext = this;中执行ContentView,因为它劫持了试图对其进行数据库的页面中的上下文。而是使用Content.BindingContext = this;
https://stackoverflow.com/questions/39989536
复制相似问题