3

I want to create a breadcrumb control that has a button at the beginning that will clear the breadcrumb items. My problem is getting that first button to wrap properly with the rest of the items. Here's my style:

<Style TargetType="{x:Type local:Breadcrumb}">
    <Setter Property="ItemTemplate">
        <Setter.Value>
            <DataTemplate>
                <Button Content="{Binding}"
                        FontSize="{Binding RelativeSource={RelativeSource AncestorType=local:Breadcrumb}, Path=BreadcrumbFontSize}" 
                        FontFamily="{Binding RelativeSource={RelativeSource AncestorType=local:Breadcrumb}, Path=BreadcrumbFont}"
                        FontWeight="{Binding RelativeSource={RelativeSource AncestorType=local:Breadcrumb}, Path=BreadcrumbFontWeight}"
                        Width="{Binding RelativeSource={RelativeSource AncestorType=local:Breadcrumb}, Path=BreadcrumbItemWidth}"
                        Height="{Binding RelativeSource={RelativeSource AncestorType=local:Breadcrumb}, Path=BreadcrumbItemHeight}"
                        Margin="0,0,-22,10"
                        Style="{DynamicResource BreadcrumbButton}" />
            </DataTemplate>
        </Setter.Value>
    </Setter>

    <Setter Property="ItemsPanel">
        <Setter.Value>
            <ItemsPanelTemplate>
                <WrapPanel />
            </ItemsPanelTemplate>
        </Setter.Value>
    </Setter>

    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ItemsControl}">
                <WrapPanel>
                    <Button Content="Menu" Height="{Binding RelativeSource={RelativeSource AncestorType=local:Breadcrumb}, Path=BreadcrumbItemHeight}"
                            Width="{Binding RelativeSource={RelativeSource AncestorType=local:Breadcrumb}, Path=BreadcrumbItemWidth}"/>
                    <ItemsPresenter Height="{TemplateBinding Height}" Width="{TemplateBinding Width}" />
                </WrapPanel> 
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

When all of the items fit on the same line it displays properly:

enter image description here

When it starts to wrap, it pushes all of the items below the "Menu" button:

enter image description here

Is there a way that I can update this so that the other elements do not go below the Menu button?

4

1 回答 1

1

No, the ItemsPresenter will contain another WrapPanel, i would recommend making that button part of the items (e.g. using a CompositeCollection), then it is in the same WrapPanel.

于 2012-07-17T14:06:00.923 回答