Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将样式应用于Silverlight 4中的子元素_Silverlight_Styles - Fatal编程技术网

将样式应用于Silverlight 4中的子元素

将样式应用于Silverlight 4中的子元素,silverlight,styles,Silverlight,Styles,在Silverlight 4中(使用Expression Blend 4),如何在包含它的边框的样式中更改文本框的字体大小?我正在将样式从WPF转换为Silverlight(总是很有趣)。以下是我所拥有的: <Style x:Key="Title" TargetType="Border"> <Setter Property="TextBlock.VerticalAlignment" Value="Center"/> <Setter Property=

在Silverlight 4中(使用Expression Blend 4),如何在包含它的
边框的样式中更改
文本框的字体大小?我正在将样式从WPF转换为Silverlight(总是很有趣)。以下是我所拥有的:

<Style x:Key="Title" TargetType="Border">
    <Setter Property="TextBlock.VerticalAlignment" Value="Center"/>
    <Setter Property="TextBlock.TextAlignment" Value="Center"/>
    <Setter Property="TextBlock.FontSize" Value="48"/>
    <Setter Property="TextBlock.Foreground" Value="{StaticResource TextForeground}"/>
    <Setter Property="VerticalAlignment" Value="Top"/>
    <Setter Property="HorizontalAlignment" Value="Stretch"/>
    <Setter Property="Background" Value="{StaticResource TitleBackground}"/>
    <Setter Property="Padding" Value="25,0"/>
</Style>

它不起作用。它在设计器中给了我以下异常:

编辑:


好的,我知道这在WPF中是可能的。在Silverlight中,这是不可能的(不按照Xin的建议采用整个主题结构?

事实上,您可能可以从Silverlight toolkit主题中得到您想要的东西。你可以找到它(主题->主题浏览器)

更新:

首先,您需要创建一个继承自主题(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);
        }
    }
//
///隐式地将边界主题应用于其所有后代
///框架元素。
/// 
///预演
公共课主题:主题
{
/// 
///存储对Uri的引用,该Uri引用类的主题资源。
/// 
私有静态Uri ThemeResourceUri=新Uri(“/theming;component/Theme.xaml”,UriKind.Relative);
/// 
///初始化ExpressionDarkTheme类的新实例。
/// 
公共主题()
:base(ThemeResourceUri)
{
var a=资源URI;
}
/// 
///获取一个值,该值指示此主题是否为应用程序主题。
/// 
///应用程序实例。
///如果此主题是应用程序主题,则为True。
公共静态bool getisapplicationteme(应用程序应用程序)
{
return GetApplicationThemeUri(app)==ThemeResourceUri;
}
/// 
///设置一个值,该值指示此主题是否为应用程序主题。
/// 
///应用程序实例。
///如果此主题应为应用程序主题,则为True。
公共静态无效设置为Application Iteme(应用程序应用程序,布尔值)
{
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>


就这样。您应该能够看到应用于边框和文本块的样式。:)

我认为在Silverlight 4中不可能做到这一点…@Xin,不是很有帮助,但很诚实。谢谢:)我很困惑。这对我的处境有什么帮助。我想造一个时钟,而你却给了我火箭飞船的蓝图。