Binding of TextBlock inside Custom Control to dependency property of the same Custom Control?

Up vote 1 down vote favorite 1 share g+ share fb share tw.

I have a custom control with a TextBlock inside it: And this Custom control has a dependency property: public class CustControl : Control { static CustControl() { DefaultStyleKeyProperty. OverrideMetadata(typeof(CustControl), new FrameworkPropertyMetadata(typeof(CustControl))); } public readonly static DependencyProperty CustNoProperty = DependencyProperty. Register("CustNo", typeof(string), typeof(CustControl), new PropertyMetadata("")); public string CustNo { get { return (string)GetValue(CustNoProperty); } set { SetValue(CustNoProperty, value); } } } I want the value of "CustNo" property be transfered in "Text" property of TextBlock in each instance of the Custom Control.

But my: Text="{Binding Source=CustControl,Path=CustNo}" isn't working. Isn't working also with Path=CustNoProperty: Text="{Binding Source=CustControl,Path=CustNoProperty}" c# wpf data-binding xaml custom-controls link|improve this question asked Dec 6 '09 at 10:07rem1,96332058 98% accept rate.

Ps there's an excellent (if a little dated) dnrtv show on creating custom controls at dnrtv.com/default.aspx?showNum=72 – IanR Dec 6 '09 at 10:18 Yes it works. Thank you! – rem Dec 6 '09 at 10:30.

Try the answers to this SO question. I think you'll want the third example. Ie: {Binding Path=CustNo, RelativeSource={RelativeSource TemplatedParent}}.

Simeon, thank you. Your answer is all I need. I'm sorry that it's impossible to select several identical right answers, which were posted at the same time as both accepted.

– rem Dec 6 '09 at 10:33 Well mine answer was posted 2 minutes before Ian's, but you had to be there at the time to notice. No stress. Maybe next time... – Simeon Pilgrim Dec 6 '09 at 18:51.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions


Thank You!
send