none
WPF资源定义位置的问题 RRS feed

  • 问题

  • vs.net 2010英文版中,如果定义如下,则所有窗体中的datagrid都会按定义的方式显示

    <Application x:Class="my.App"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        StartupUri="Login.xaml"
        ShutdownMode="OnLastWindowClose"
        DispatcherUnhandledException="Application_DispatcherUnhandledException">
        <Application.Resources>
          
            <Style TargetType="DataGrid">
                <Setter Property="ColumnHeaderHeight" Value="35"/>
                <Setter Property="RowHeaderWidth" Value="15"/>
                <Setter Property="HorizontalGridLinesBrush" Value="#F0F8FF"/>
                <Setter Property="VerticalGridLinesBrush" Value="#F0F8FF" />
                <Setter Property="RowHeight" Value="25"/>
            </Style>
            <Style TargetType="DataGridColumnHeader">
                <Setter Property="Foreground" Value="Green"/>
            </Style>
        </Application.Resources>
    </Application>

    但是如果分离出资源文件,象下面这样定义,则不能正常显示:

    <Application x:Class="my.App"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        StartupUri="Login.xaml"
        ShutdownMode="OnLastWindowClose"
        DispatcherUnhandledException="Application_DispatcherUnhandledException">
        <Application.Resources>
            <ResourceDictionary Source="/PresentationFramework.Aero, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35;component/themes/aero.normalcolor.xaml">
                <ResourceDictionary.MergedDictionaries>
                    <ResourceDictionary Source="Resources/DefaultControlStyles.xaml"/>
                </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
        </Application.Resources>
    </Application>

    其中:DefaultControlStyles.xaml定义如下:

    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
      
        <!--DataGrid-->
        <Style TargetType="DataGrid">
            <Setter Property="ColumnHeaderHeight" Value="35"/>
            <Setter Property="RowHeaderWidth" Value="15"/>
            <Setter Property="HorizontalGridLinesBrush" Value="#F0F8FF"/>
            <Setter Property="VerticalGridLinesBrush" Value="#F0F8FF" />
            <Setter Property="RowHeight" Value="25"/>
        </Style>
        <Style TargetType="DataGridColumnHeader">
            <Setter Property="Foreground" Value="Green"/>
        </Style>

    </ResourceDictionary>

    请问如何解决此问题?谢谢。

    2010年4月30日 1:11