Horizontally centered horizontal ItemsControl
How can I create horizontally oriented ItemsControl
, where items are aligned the same way how these two labels are aligned in this G开发者_C百科rid
?
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Grid.Column="1">Text 1</Label>
<Label Grid.Column="3">Text 2</Label>
</Grid>
I already have a View for the items, so using ItemsTemplate
is probably not an option.
Resources
Here are some tutorials and articles about creating your own custom panel. Hope this will help someone with similar problem...
UniformGrid for Silverlight
Animate WPF Datatemplate when item added to Listbox? Creating Custom Panels In WPF FishEyePanel/FanPanel - Examples of custom layout panels in WPF WPF - A Constraining Stack PanelAbout the closest you could get without writing your own panel would be:
<ItemsControl ItemsSource="{Binding TheItems}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Rows="1"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style>
<Setter Property="Control.HorizontalAlignment" Value="Center"/>
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
Note that I'm .NET-less at the moment so cannot test the above.
精彩评论