实际上,您可能可以从silverlight工具包主题中获得所需内容。你可以找到它here(主题 - >主题浏览器)。
更新:
首先,你需要创建从主题(System.Windows.Controls.Theming)继承的类。我基本上从源代码复制并重命名它。
/// <summary>
/// Implicitly applies the border theme to all of its descendent
/// FrameworkElements.
/// </summary>
/// <QualityBand>Preview</QualityBand>
public class BorderTheme : Theme
{
/// <summary>
/// Stores a reference to a Uri referring to the theme resource for the class.
/// </summary>
private static Uri ThemeResourceUri = new Uri("/theming;component/Theme.xaml", UriKind.Relative);
/// <summary>
/// Initializes a new instance of the ExpressionDarkTheme class.
/// </summary>
public BorderTheme()
: base(ThemeResourceUri)
{
var a = ThemeResourceUri;
}
/// <summary>
/// Gets a value indicating whether this theme is the application theme.
/// </summary>
/// <param name="app">Application instance.</param>
/// <returns>True if this theme is the application theme.</returns>
public static bool GetIsApplicationTheme(Application app)
{
return GetApplicationThemeUri(app) == ThemeResourceUri;
}
/// <summary>
/// Sets a value indicating whether this theme is the application theme.
/// </summary>
/// <param name="app">Application instance.</param>
/// <param name="value">True if this theme should be the application theme.</param>
public static void SetIsApplicationTheme(Application app, bool value)
{
SetApplicationThemeUri(app, ThemeResourceUri);
}
}
然后,您只需创建一个资源字典并将其命名为Theme.xaml,并将所有样式放入其中。
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="Border">
<Setter Property="VerticalAlignment" Value="Top"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="Background" Value="{StaticResource TitleBackground}"/>
<Setter Property="Padding" Value="25,0"/>
</Style>
<Style TargetType="TextBlock">
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="TextAlignment" Value="Center"/>
<Setter Property="FontSize" Value="48"/>
<Setter Property="Foreground" Value="{StaticResource TextForeground}"/>
</Style>
</ResourceDictionary>
最后,用它包裹你的边框!
<local:BorderTheme>
<Border>
<TextBlock Text="TextBlock"/>
</Border>
</local:BorderTheme>
就是这样。您应该能够看到应用于边框的样式以及TextBlock。 :)
我不认为这是可以做到这一点在Silverlight 4 ... – 2011-04-27 02:14:28
@辛,不是很有帮助,但诚实。谢谢:) – Jordan 2011-04-27 14:51:44