Binding a unit label in WPF textbox

[亡魂溺海] 提交于 2019-12-08 02:32:29

问题


I'm binding a pressure to a textbox. The pressure could be in PSI, KPA, BARS, etc. I would like to display the unit inside the textbox next to the value. There doesn't seem to be a way to bind the Units string property in my viewmodel to the StringFormat option of the value binding. Is there any way to accomplish this without retemplating the textbox?


回答1:


You can use MultiBinding:

<TextBox>
    <TextBox.Text>
        <MultiBinding StringFormat="{}{0} {1}">
            <Binding Path="Pressure" />
            <Binding Path="Unit"/>
        </MultiBinding>
    </TextBox.Text>
</TextBox>


来源:https://stackoverflow.com/questions/14758318/binding-a-unit-label-in-wpf-textbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!