开发者

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 Panel


About 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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜