Saturday, October 6, 2012

How to access textblock inside Datatemplate in combobox?

How to access textblock inside Datatemplate in combobox?

I am trying to Bind the TextBlock inside ComboBox through Code. I am able to bind the textblock sucessfully but For some reasons TextBlock doesnt display Text Values.

I have mechanism which checks for the selected values and there I am getting the selected values without any problem.

So to conclude, My binding is working fine but I am missing out something hence textblock is not displaying text that is bound with it.

This is the code I am using for Binding: where "lObjTextBlock" is TextBlock inside of ComboBox.

TextBlock lObjTextBlock = (TextBlock)ComboBox.ItemTemplate.LoadContent();   Binding lObjBinding = new Binding();  lObjBinding.Path = new PropertyPath("[" + lObjMap.PropertyName + "]");  lObjTextBlock.SetBinding(TextBlock.TextProperty, lObjBinding); 

This is the XAML for the TextBlock:

<my:HComboBox Name="cmbRefDoctor"> <my:HComboBox.ItemTemplate>     <DataTemplate>                 <TextBlock x:Name="txtRefDoctorName" />     </DataTemplate> </my:HComboBox.ItemTemplate> </my:HComboBox> 

Once again : My problem is that TextBlock is not displaying any Text althought values are being set.

Would love to get all possible suggestions. Thanks in advance.

Answers & Comments...




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog