我试图绑定到C ++ / CX的Windows应用商店应用程序(与Visual Studio 2013编译器一起编译)中的GridLength实例,但是由于某些原因,我在运行时始终遇到以下错误:
Error: Converter failed to convert value of type 'Windows.Foundation.IReference`1<Windows.UI.Xaml.GridLength>' to type 'GridLength'; BindingExpression: Path='MyHeight' DataItem='MyNamespace.MyObject'; target element is 'Windows.UI.Xaml.Controls.RowDefinition' (Name='null'); target property is 'Height' (type 'GridLength').
我的代码基本上看起来像:
namespace MyNamespace
{
[Windows::UI::Xaml::Data::Bindable]
public ref class MyObject sealed
{
property Windows::UI::Xaml::GridLength MyHeight
{
Windows::UI::Xaml::GridLength get() { return myHeight; }
}
}
}
和我的XAML文件基本上看起来像:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="{Binding MyHeight}"/>
</Grid.RowDefinitions>
</Grid>
仅供参考,我类中的其他属性可以正确绑定。该问题似乎仅与GridLength值结构有关。显然可以正确找到该属性,但是由于某种原因它无法匹配类型。
RowDefinition不是FrameworkElement,因此它没有DataContext。绑定在这里不起作用。不过,您可以在该行中放置一个Rectangle,将行高度设置为Auto并将Rectangle.Height绑定到所需的属性。在某些情况下这可能会起作用。对于其他人,可能会有更好的解决方案,但是您需要指定要实现的目标。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句