silverlight – 使我的Usercontrol的属性可绑定

silverlight – 使我的Usercontrol的属性可绑定,第1张

概述我创建了一个自定义用户控件,我在我的主xaml控件上使用: <Controls:CustomControl Width="200" Height="20" TotalCount="{Binding TotalRecordCount}" SuccessCount="{Binding ValidationCount}" ErrorCount="{Binding ValidationErrorCou 我创建了一个自定义用户控件,我在我的主xaml控件上使用:

<Controls:CustomControl  WIDth="200" Height="20" TotalCount="{Binding TotalRecordCount}" SuccessCount="{Binding ValIDationCount}" ErrorCount="{Binding ValIDationErrorCount}" margin="0,5,0"  HorizontalAlignment="left"> </Controls:CustomControl>

我想让我的自定义usercontrol的私有变量是ErrorCount,SuccessCount和总计数(类型为int32)Bindable所以我可以绑定值给它们.现在,当我尝试将它绑定到我的项目源时,它会给出以下错误e异常消息是“类型为’System.windows.Data.Binding’的对象’无法转换为’system.int32’类型’

非常感谢,
米歇尔

解决方法 您需要使用DependencyProperty实现PropertIEs不要使用私有变量来保存这些值.这是一个例子: –

#region public int SuccessCount    public int SuccessCount    {        get { return (int)GetValue(SuccessCountProperty); }        set { SetValue(SuccessCountProperty,value); }    }    public static Readonly DependencyProperty SuccessCountProperty =        DependencyProperty.Register(            "SuccessCount",typeof(int),typeof(CustomControl),new PropertyMetadata(0,OnSuccessCountPropertyChanged));    private static voID OnSuccessCountPropertyChanged(DependencyObject d,DependencyPropertyChangedEventArgs e)    {        CustomControl source = d as CustomControl;        int value = (int)e.NewValue;        // Do stuff when new value is assigned.    }    #endregion public int SuccessCount
总结

以上是内存溢出为你收集整理的silverlight – 使我的Usercontrol的属性可绑定全部内容,希望文章能够帮你解决silverlight – 使我的Usercontrol的属性可绑定所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1005460.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-22
下一篇2022-05-22

发表评论

登录后才能评论

评论列表(0条)

    保存