【问题标题】:xaml Application Resource Valuexml 应用程序资源值
【发布时间】:2009-05-21 15:37:56
【问题描述】:

我想设置一个应用程序范围的值,即 TextHeight(其他也是),但我似乎找不到参考。 IOW,将 Text Height 设置为各种样式的 StaticResource 等。

【问题讨论】:

    标签: wpf xaml resources


    【解决方案1】:

    读完这个问题后,我的大脑有点疼。让我回答,好像我真的明白你在问什么。

    <Application x:Class="WpfApplication1.App"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        StartupUri="Window1.xaml">
        <Application.Resources>
            <Style TargetType="TextBox">
                <Setter Property="FontSize" Value="100"/>
            </Style>
        </Application.Resources>
    </Application>
    

    澄清:

    <Application x:Class="WpfApplication1.App"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        StartupUri="Window1.xaml">
        <Application.Resources>
            <sys:Double x:Key="MyTextHeight">32</sys:Double>
            <Style TargetType="TextBlock">
                <Setter Property="FontSize" Value="{StaticResource MyTextHeight}"/>
            </Style>
        </Application.Resources>
    </Application>
    

    注意第 4 行,然后是新的 Double(还要注意类型必须与参数的类型匹配——我最初尝试 sys:Int32 导致一些有趣的不相关异常)。

    【讨论】:

    • 我的道歉,通宵结束。我想要... Value="{StaticResource MyTextHeight}"/>。所以我希望能够在应用程序资源级别定义 MyTextHeight。再次感谢
    • 我最真诚的矛盾!请将此复选标记作为我尊重的一个小标志。
    • 哥们,别喝咖啡了。大量上瘾。
    • 不是 BlackAdder 的粉丝? “我是消化不良的、精神分裂症的,甚至是因为引起了这种周血反应。”
    • 我不知道你在说什么。不过,为了你的努力,这里有一袋钱……我不会给你的。
    猜你喜欢
    • 2012-04-20
    • 2010-10-16
    • 2017-12-03
    • 2012-09-18
    • 1970-01-01
    • 2012-06-09
    • 2012-07-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多