In the following XAML, how can I use _xyzStackPanel
in the code behind? Is this not possible when we use DataTemplate
? I need to show/hide this stackpanel, what is the best way?
Can I use the VisualStateManager
here? Could someone provide example please, thanks.
<ListBox ... >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Name="_xyzStackPanel" ...>开发者_开发百科
..............
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Thanks,
Voodoo
EDIT:
I wonder if it would be better to add the StackPanel in the codebehind instead of always having it there and hiding it......BUT, how can I add to the DataTemplate in the codebehind?
Bind the Visibility of the StackPanel to the ViewModel object it represents and toggle that instead. You are using MVVM, right??
精彩评论