在 WP7 用户控件中进行数据绑定时获取 AG_E_PARSER_BAD_PROPERTY_VALUE [英] Getting AG_E_PARSER_BAD_PROPERTY_VALUE while data binding in WP7 User control

查看:16
本文介绍了在 WP7 用户控件中进行数据绑定时获取 AG_E_PARSER_BAD_PROPERTY_VALUE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Silverlight 中创建了一个用户控件,它基本上可以为矩形的大小设置动画.

I have created a user control in Silverlight which basically animates the size of a rectangle.

    <StackPanel x:Name="LayoutRoot" Background="Gray"><StackPanel.Resources>
        <Storyboard x:Name="myStoryboard" Completed="myStoryboard_Completed">
            <DoubleAnimation x:Name="ExpandY" From="{Binding Path=From}" To="{Binding Path=To}" Duration="00:00:2" 
            Storyboard.TargetName="myScaleTransform" 
            Storyboard.TargetProperty="ScaleY">
                <DoubleAnimation.EasingFunction>
                    <BackEase Amplitude="0.0" EasingMode="EaseInOut" />
                </DoubleAnimation.EasingFunction>
            </DoubleAnimation>
        </Storyboard>            
    </StackPanel.Resources>

    <Rectangle  x:Name="myRectangle" MouseLeftButtonDown="Mouse_Clicked" 
 Fill="{Binding Path=Barcolor}" Width="35" Height="50" RadiusX="2" RadiusY="2"  MouseEnter="myRectangle_MouseEnter" Stroke="White" StrokeThickness="0" MouseLeave="myRectangle_MouseLeave">
        <Rectangle.RenderTransform>
            <ScaleTransform x:Name="myScaleTransform" CenterY="50"/>
        </Rectangle.RenderTransform>
    </Rectangle>
</StackPanel>

我已经绑定了一个实现 INotifyPropertyChanged 的​​对象作为数据上下文.

I have bound an object which implements INotifyPropertyChanged to this as the data context.

现在,当我在 ASP.NET 主机页面中将它作为 Silverlight 控件运行时,整个事情都运行良好.但是当我移植相同的代码来创建 WP7 用户控件时,我得到 AG_E_PARSER_BAD_PROPERTY_VALUE 指向 From="{Binding Path=From}" 在双动画ExpandY"中的位置.

Now, the whole thing works fine when I run it as a silverlight control in an ASP.NET host page. But when I port the same code to create a WP7 user control I get the AG_E_PARSER_BAD_PROPERTY_VALUE pointing to the location where From="{Binding Path=From}" is located in the Double animation "ExpandY".

Silverlight 控件和 WP7 用户控件中的数据绑定方式有什么不同吗?

Is there anything different how the data is bound in a silverlight control and a WP7 user control?

推荐答案

这里的问题是 DoubleAnimation 不是 FrameworkElement 并且在 Silverlight for WP7 中你只能设置FrameworkElement 上的绑定.为了实现这种效果,您需要在代码隐藏中操作动画,可能是通过将行为包装到单独的 UserControl 中.

The problem here is that DoubleAnimation is not a FrameworkElement and in Silverlight for WP7 you can only set a binding on a FrameworkElement. In order to achieve this effect you'll need to manipulate the animation in code-behind, possibly by wrapping the behavior up into a separate UserControl.

与此问题相同:绑定到故事板中的To"

这篇关于在 WP7 用户控件中进行数据绑定时获取 AG_E_PARSER_BAD_PROPERTY_VALUE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆