资源字典无法访问

时间:2013-07-29 10:08:28

标签: c# wpf resourcedictionary

我有一个Wpf项目,我在其中创建了一个资源字典,但我无法访问其中的tamplates。

在我的字典里面我有这个:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<DataTemplate x:Key="Itemaki">
        <StackPanel>
        <Grid Background="#4C747474">
            <Grid.RowDefinitions>
                <RowDefinition Height="30"/>
                <RowDefinition Height="10"/>
            </Grid.RowDefinitions>

            <Grid Grid.Row="0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="30"/>
                    <ColumnDefinition Width="100"/>
                </Grid.ColumnDefinitions>
                <Image Grid.Column="0" Source="C:\image.jpg" Stretch="Fill"/>
                <Grid Grid.Column="1" Width="90" Margin="0,0,10,0">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="20"/>
                        <RowDefinition Height="10"/>
                    </Grid.RowDefinitions>
                    <TextBlock Grid.Row="0" Text="{Binding SName}" FontSize="13" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center" />
                    <TextBlock Grid.Row="1" Text="{Binding SGenre}" FontSize="9" Foreground="#FF2AACAC" VerticalAlignment="Center" HorizontalAlignment="Center"/>
                </Grid>
            </Grid>
            <Grid Grid.Row="1">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="50"/>
                    <ColumnDefinition Width="50"/>
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Column="0" Text="{Binding SCountry}" FontSize="9" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center" />
                <TextBlock Grid.Column="1" Text="{Binding SCity}" FontSize="9" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center"/>
            </Grid>
        </Grid>
    </StackPanel>
 </DataTemplate>

我如何在我的MainWindow xaml中使用它?

1 个答案:

答案 0 :(得分:0)

在App.xaml中将其粘贴到<Application.Resources>

    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="YOUR DICTIONARY NAME.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>

希望它有所帮助。