【发布时间】:2015-10-17 21:47:11
【问题描述】:
谁能解释如何评估 XAML 数据绑定表达式?我有一个带有注册属性 VisualState 的控件。
public CardStates VisualState
{
get
{
return (CardStates)this.GetValue(VisualStateProperty);
}
set
{
this.SetValue(VisualStateProperty, value);
}
}
public static readonly DependencyProperty VisualStateProperty = DependencyProperty.RegisterAttached("VisualStateProperty", typeof(CardStates), typeof(StateManager), new PropertyMetadata(null, (s, e) => { }));
在 xaml 中,我尝试将值绑定到此属性。状态存在父级的 DataContext 对象。
<local:CardControl VisualState="{Binding State.Value}" />
XamlTypeInfo.g.cs 中生成的代码如下所示
private void set_4_CardControl_VisualState(object instance, object Value)
{
var that = (global::MeetEric.UI.Controls.CardControl)instance;
that.VisualState = (global::MeetEric.ViewModels.CardStates)Value;
}
此代码引发 InvalidCastException,因为 Value 的值是 Windows.UI.Xaml.Data.Binding 对象。
我是否遗漏了一些明显的东西来启用数据绑定?我需要某种形式的转换器吗?
【问题讨论】:
标签: c# xaml winrt-xaml win-universal-app