Add object into WPF listview with ItemContainerStyle
I have a listview, with ItemContainerStyle, call StyleA.
the listview has itemSource of an ObservableCollection, which contain my clas开发者_StackOverflows objects. StyleA will bind to the property of my class object according to my template.
It works properly.
Now I want to include a textbox into the listview, like this:
<ListView ItemContainerStyle="{StaticResource StyleA}">
<TextBox Text="Hello World"/>
</ListView>
It's not working, because StyleA can't bind with the class object's property. (because it is TextBox).
I had tried <TextBox OverrideDefaultStyle="True" Text="Hello World"/>
, but same error too.
Any help?
You may use ItemContainerStyleSelector to apply different item styles.
My solution is, I use a Label to contain a TextBlock, and when I need to modified the text, I change the content of Label into TextBox, set the TextBlock's text into TextBox, so I can modify the text, after Enter key, save the text, and change Label content to TextBlock again.
Maybe not an elegant solution, but it works for me.
精彩评论