gpt4 book ai didi

c# - 如何在图 block 上设置边框

转载 作者:太空宇宙 更新时间:2023-11-03 13:22:21 25 4
gpt4 key购买 nike

我尝试在 Tile 上设置边框,但它就是不想显示。

   <mah:Tile Content="Tile" HorizontalAlignment="Left" Margin="692,250,0,0" VerticalAlignment="Top" BorderBrush="#FFE01C1C" BorderThickness="3"/>

没有抛出任何错误,我在源代码中也看不到,https://github.com/MahApps/MahApps.Metro/blob/master/MahApps.Metro/Themes/Tile.xaml ,为什么这行不通。有帮助吗?

最佳答案

您应该编辑默认的 Tile 主题。

1) 添加ResourceDictionary (TileTheme.xaml):

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mah="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro">
<Style TargetType="mah:Tile">
<Setter Property="Width"
Value="140" />
<Setter Property="Height"
Value="140" />
<Setter Property="Margin"
Value="3" />
<Setter Property="Foreground"
Value="White" />
<Setter Property="Background"
Value="{DynamicResource AccentColorBrush}" />
<Setter Property="HorizontalContentAlignment"
Value="Center" />
<Setter Property="VerticalContentAlignment"
Value="Center" />
<Setter Property="RenderTransformOrigin"
Value="0.5,0.5" />
<Setter Property="TitleFontSize"
Value="16"/>
<Setter Property="CountFontSize"
Value="28"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="mah:Tile">
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
<Grid Background="{TemplateBinding Background}">
<StackPanel VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Orientation="Horizontal">
<ContentPresenter RecognizesAccessKey="True" />
<TextBlock Text="{TemplateBinding Count}"
FontSize="{Binding CountFontSize, RelativeSource={RelativeSource TemplatedParent}}"
VerticalAlignment="Center" />
</StackPanel>

<Label Grid.ColumnSpan="2"
HorizontalAlignment="Left"
VerticalAlignment="Bottom"
Foreground="{TemplateBinding Foreground}">
<AccessText Text="{Binding Title, RelativeSource={RelativeSource TemplatedParent}}"
Foreground="{TemplateBinding Foreground}"
TextWrapping="Wrap"
FontSize="{Binding TitleFontSize, RelativeSource={RelativeSource TemplatedParent}}"
Margin="3" />
</Label>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="Button.IsPressed"
Value="True">
<Setter Property="RenderTransform">
<Setter.Value>
<ScaleTransform ScaleX="0.98"
ScaleY="0.98"
CenterX="0.5"
CenterY="0.5" />
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>

2) 将此资源字典导入您的应用程序(通过编辑 App.xaml):

<Application ...>
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="TileTheme.xaml" />
</ResourceDictionary.MergedDictionaries>

</ResourceDictionary>
</Application.Resources>
</Application>

Here是示例解决方案。

关于c# - 如何在图 block 上设置边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23711666/

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