在 WP7 用户控件中进行数据绑定时获取 AG

编程入门 行业动态 更新时间:2024-10-27 19:21:29
本文介绍了在 WP7 用户控件中进行数据绑定时获取 AG_E_PARSER_BAD_PROPERTY_VALUE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我在 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-25 14:29:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1117475.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控件   数据   用户   AG

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!