开发者

How to make ListView change ItemControl to VirtualizingStackPanel at runtime

OK, so, I have a ListView-derived control that changes Grouping and ItemsSource on the fly. When I group such that the scrollbars dissapear, and then change my ItemsSource to a different ICollectionView, my scrollbars do not return.

The basic problem is that ListView changes to a VirtualizedStackPanel when grouping is activated and does not ch开发者_JS百科ange back when grouping is de-activated.

I don't mind that virtualization is disabled when grouping--this is not a problem. What I need is a way to make the ListView regenerate it's ItemPanel when I change the ItemsSource.


Could you add an event handler to the SourceUpdated event and then reset the ItemsPanelTemplate to a template defined in your Resources?

Something like:

public MyWindow()
{
   InitializeComponent();

   MyListView.SourceUpdated += new EventHandler<DataTransferEventArgs>( OnSourceUpdated );
}

void OnSourceUpdated( object sender, DataTransferEventArgs e )
{
   MyListView.ItemsPanel = (ItemsPanelTemplate)Resources["MyItemsPanelTemplate"];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜