开发者

datatemplate in silverlight c#.net

开发者 https://www.devze.com 2023-04-09 04:57 出处:网络
i am creating a datatemplate for items in listbox and loading it using (DataTemplate)XamlReader.Load(template), where template is

i am creating a datatemplate for items in listbox and loading it using (DataTemplate)XamlReader.Load(template), where template is

string template = String.Concat(@
"<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'                                        xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<Border BorderBrush='#334873' BorderThickness='1,1,1,1' Width='450'>开发者_开发技巧;
<TextBox Height='72' HorizontalAlignment='Left' Margin='10,10,0,0'  TextChanged="OnTextChanged" VerticalAlignment="Top" Width="460" />"
...................
"</Border></DataTemplate>");

i m getting error because of "OnTextChanged" event registerd.

I want to register a event in the template code.

How to do it?


To give you an answer: as you are using a Template it's rather difficult to map an event this way because the template doesn't know where it's put into. So OnTextChanged doesn't mean a thing in this context.

You should consider bindings instead. As you allready use a DataTemplate the usual story would be to Bindd the TextBox-Text property to some model-property

<TextBox Height='72' HorizontalAlignment='Left' Margin='10,10,0,0'  Text="{Binding MyTextProperty}" VerticalAlignment="Top" Width="460" />"

Of course the DataContext here should have a property MyTextProperty but without your code (where you use the template) I can give no further details.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号