How to align horizontal content alignment in center in wrap panel. [Resolved]

Posted by Pkanwar under WPF on 12/24/2013 | Points: 10 | Views : 3136 | Status : [Member] | Replies : 1

We are using ListView and in ListView have ItemPanelTemplate in ItemPanleTemplate have been added wrap panel.Images have been added in wrap panel.
But we want to show the images alignment center, but by default images are showing left to right alignment. I have read many articles and find out that wrap panel align left to right by default.I have set also HorizontalAlignment="Center" in wrap panel, But no effect.Our code in VB.Net.
Any help regarding to that


<WrapPanel Width="{Binding (FrameworkElement.ActualWidth), RelativeSource={RelativeSource AncestorType=ScrollPresenter}}" HorizontalAlignment="Center"/>

</ListView.ItemsPanel> </ListView>


Posted by: Mauriciobertelli on: 5/13/2016 [Member] Starter | Points: 50


Try to bind MaxWidth instead of Width, and use as AncestorType the Listview. So, the new code should be:

<WrapPanel MaxWidth ="{Binding (FrameworkElement.ActualWidth), RelativeSource={RelativeSource AncestorType=ListView}}" HorizontalAlignment="Center" HorizontalAlignment="Center"/>

Pkanwar, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response