我想創建一個麪包屑控件,該控件在開始時會有一個按鈕來清除麪包屑項目。我的問題是讓第一個按鈕正確包裝其餘的項目。這是我的風格:WPF自定義ItemsControl - 包裝問題
<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>
當所有的物品放置在同一行會顯示正確:
當開始換行,它推動所有項目下面的「菜單「按鈕:
有沒有辦法,我可以更新這個讓其他元素不走下面的一種方式菜單按鈕?
[Chris](https://stackoverflow.com/users/71904/chris-klepeis),請你可以發佈你的按鈕樣式?我想創建類似的東西。 – 2017-08-05 07:32:19
@GailBowen對不起,我沒有這個代碼了。看看這裏的答案https://stackoverflow.com/questions/5727382/breadcrumb-style-with-wpf-listview – 2017-08-07 13:39:52