日期:2014-05-17  浏览次数:20935 次

WPF,访问资源字典为什么报错呢?
新建一个名为"Dictionary1"的资源字典:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Style x:Key="aa">
        <Setter Property="Control.Template">
            <Setter.Value>
                <ControlTemplate>
                    <Border Background="Red">
                        <ContentPresenter />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>


在项目中使用:

<Window x:Class="WPF3.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="800" Width="1105">
    <Window.Resources>
        <Style x:Key="aa">
            <Setter Property="Control.Template" >
                <Setter.Value>
                    <ControlTemplate>
                        <Grid>
                            <Control Style="{DynamicResource aa}">
                                <Control.Resources>
                                   <ResourceDictionary Source="pack://application:,,,/WPF3;component/Dictionary1.xaml"/> 
                                </Control.Resources>
                         &