gpt4 book ai didi

wpf - WrapPanel 中的无边框图像按钮

转载 作者:行者123 更新时间:2023-12-04 06:55:58 25 4
gpt4 key购买 nike

我正在尝试使用包含艺术品的无缝 ImageButtons 创建 WrapPanel。我将以下 ContentTemplate 放在一起,希望它能提供所需的无缝外观;然而,每个按钮周围都有一条细白线。任何人都可以引导我朝着正确的方向前进吗?

<Button.ContentTemplate>
<DataTemplate DataType="{x:Type local:ArtInfo}">
<Border Name="border" BorderThickness="0" BorderBrush="blue" Height="280" Width="250" Background="#262c40">
<StackPanel>
<Grid>
<Grid.Resources>
<local:MyConverter x:Key="MyConverter"></local:MyConverter>
<ObjectDataProvider x:Key="Properties.Settings" ObjectType="{x:Type lcl:Properties.Settings}" />
</Grid.Resources>
<Image Name="ArtImage" Margin="10,15,0,0" Height="195" Width="195" VerticalAlignment="Top" >
<Image.Source>
<Binding Path="ArtImage"/>
</Image.Source>
</Image>
</Grid>
<TextBlock Text="{Binding Path=ArtClass}" Margin="10,-17,0,0" FontSize="11" Foreground="white" />
<TextBlock Text="{Binding Path=Student}" Margin="10,0,0,0" FontSize="11" Foreground="white" />
<TextBlock Text="1998" Margin="10,0,0,0" FontSize="11" Foreground="white" />
</StackPanel>
</Border>
</DataTemplate>
</Button.ContentTemplate>

最佳答案

ContentTemplate 告诉 WPF 如何在 Button 内显示内容——Button 镶边(例如边框和背景)保持不变,并且模板化的内容显示在该镶边的内部和上方。

您想要替换 Button、边框等的整个外观,而不仅仅是自定义其内容的显示方式。为此,您需要改用 Template 属性。 Button.Template 的值是 ControlTemplate 而不是 DataTemplate。在该 ControlTemplate 中,您可以使用 ContentPresenter 来显示“数据模板化”内容。

在您的情况下,由于您的 DataTemplate 正在完成所有工作,您可以使用原始 ContentPresenter 作为模板:

<Button.Template>
<ControlTemplate TargetType="Button">
<ContentPresenter />
</ControlTemplate>
</Button.Template>

但是,如果您的所有按钮都使用相同的背景,您可以将其移动到 ControlTemplate 中:
<Button.Template>
<ControlTemplate TargetType="Button">
<Border BorderBrush="Blue" ...>
<ContentPresenter />
</Border>
</ControlTemplate>
</Button.Template>

然后,您可以从 DataTemplate 中删除 Border。只有当您计划将相同的 Button.Template 与其他内容模板重用并希望在不同类型的内容中保持 Button 的外观一致时,这才真正重要。

关于wpf - WrapPanel 中的无边框图像按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2572501/

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