我试图在Tile上设置Border,但它只是不想显示。
<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中看到,为什么这不起作用。有什么帮助吗?
答案 0 :(得分:1)
您应该修改默认的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是示例解决方案。