gpt4 book ai didi

WPF 自定义 ItemsControl - 包装问题

转载 作者:行者123 更新时间:2023-12-02 00:29:19 25 4
gpt4 key购买 nike

我想创建一个面包屑控件,它在开头有一个按钮,可以清除面包屑项目。我的问题是让第一个按钮与其余项目正确包裹。这是我的风格:

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

当所有项目都位于同一行时,它会正确显示:

enter image description here

当它开始换行时,它会将所有项目推送到“菜单”按钮下方:

enter image description here

有没有办法可以更新它,以便其他元素不会位于菜单按钮下方?

最佳答案

不,ItemsPresenter 将包含另一个 WrapPanel,我建议将该按钮作为项目的一部分(例如使用 CompositeCollection ),然后它位于相同的WrapPanel

关于WPF 自定义 ItemsControl - 包装问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11524168/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com