允许用户在DataTemplate中切换Binding for Label [英] Allow user to switch Binding for Label inside DataTemplate

查看:71
本文介绍了允许用户在DataTemplate中切换Binding for Label的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!如何更改Binding,例如,点击按钮?



列表框

...



Hello! How can i change Binding ,for example, by clicking a button?

Listbox
...

<ListBox x:Name="dev_listbox" Background="#FF575652" BorderBrush="{x:Null}" GotFocus="dev_listbox_GotFocus" MouseDoubleClick="dev_listbox_MouseDoubleClick" >
<ListBox.ItemContainerStyle><Style TargetType="{x:Type ListBoxItem}"><Setter Property="Height" Value="26"  /></Style></ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate >
<Label Content="{Binding modificationTime,Converter={StaticResource formatter}}"/ >
..
..
</Listbox>





无论如何都要保存Binding的名字想要使用,例如,string bindingName = fileSize而不是modifyTime。所以:< Label Content ={Binding bindingName>



希望得到你的帮助。



Is there anyway to save name of Binding which i want to use, for example, string bindingName = fileSize instead of modificationTime. So : <Label Content="{Binding bindingName>

Hope for your help.

推荐答案

您好Elgars,



您需要以双向模式绑定标签的内容。数据模板表示的项目应实现INotifyPropertyChanged。



当您想要更改标签的内容时,只需更改绑定到标签的属性的值。简单如下:)
Hi Elgars,

You need to bind the Content of the label in two-way mode. The items represented by the Data-Template should implement INotifyPropertyChanged.

When you want to change the Content of the label just change the value of the property that is binded to the label. Simple as that :)


这篇关于允许用户在DataTemplate中切换Binding for Label的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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