具有customcontrol属性的数据绑定 [英] Databinding with customcontrol properties

查看:93
本文介绍了具有customcontrol属性的数据绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

我创建了customcontrol,其中包括诸如文本块,按钮,滑块等控件.在customcontrol中,我为重要的controlproperties创建了公共属性,我希望向使用我的customcontrol的客户展示给外部.例如我的mycontrol
中的textblock text属性

Hi!

I have created customcontrol which includes controls like textblock, buttons, sliders etc. In customcontrol I have created public properties for vital controlproperties what I like to show outside to client who is using my customcontrol. For example my textblock text property in mycontrol

/// Public property of customcontrol header
public string Header
     {
          get { return txtBlockHeader.Text;  }
          set { txtBlockHeader.Text = value; }
      }



在客户端,我可以看到我的customcontrol,也可以看到我的customcontrol属性"Header",就像我通常对属性所做的一样,但是,当我尝试在我的dataClass属性和我的customcontrol属性之间设置数据绑定时,我碰壁了.这是我尝试制作绑定的方法



In clientside I can see my customcontrol and I can see my customcontrol property "Header" like I usually do with properties, BUT when I try to set databinding between my dataClass property and my customcontrol property I hit the wall. Here how I try to make bindings

//create bidings between dataClass property and customcontrol property
Binding binding = new Binding("Header");
binding.Mode = BindingMode.TwoWay;
binding.Source = dataClass;

//here I cant find Setbinding method like I usually do...
MyCustomControl.Header.SetBinding(....



希望你有主意:)

干杯!



Hope you got idea :)

Cheers!

推荐答案

尝试将Header属性更改为

Try changing the Header property to,

public string Header
     {
          get { return txtBlockHeader.GetValue(TextBox.TextProperty).ToString();  }
          set { txtBlockHeader.SetValue(TextBox.TextProperty, value); }
      }



:thumbsup:标记为答案"确实对您有帮助.



:thumbsup: Mark it as Answer is it really helped you.


您好Raistu,

也许有些误解,但是:
您将Header属性声明为字符串,并希望它具有SetBinding-方法?因此,要么通过Header属性公开TextBlockControl(txtBlockHeader),要么让Control处理绑定.
Hi Raistu,

Maybe there is some misunderstanding, but:
You declared the Header property as string and expect to have it a SetBinding - method? So either expose the TextBlockControl (txtBlockHeader) through the Header property, or let the Control handle the Binding.


这篇关于具有customcontrol属性的数据绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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