简体   繁体   中英

TextBox Placeholder text while also Binding to ListBox.SelectedItem

如何将文本框绑定到ListBox的Selected Item,我怎么还有一个占位符文本(.Text =“Whatever”)?

When do you want this placeholder text to display? When there is no SelectedItem?

You could use PriorityBinding which will allow you to provide a list of bindings and it will use the first that produces a result.

Something like:

<TextBox> 
   <TextBox.Text>
     <PriorityBinding>
       <Binding Path="myListBox.SelectedItem"/>
       <Binding Source="Default Text"/>
     </PriorityBinding>
   </TextBox.text>
 </TextBox>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM