如何从datatemplate中引用静态资源

时间:2013-10-17 22:52:22

标签: c# xaml windows-phone-8 datatemplate

我有以下问题:

<DataTemplate x:Key="OrganisationsItemTemplate">
            <StackPanel VerticalAlignment="Top" Margin="5,0,0,0">
                <Button Command="{Binding Path=DataContext.LoadSpacesCommand, ElementName=OrganisationList}" CommandParameter="{Binding}" Padding="-5,0,-5,-5" Margin="-7,-12,-7,-7" Height="auto" BorderThickness="0" HorizontalAlignment="Left" VerticalAlignment="Stretch" HorizontalContentAlignment="Left" UseLayoutRounding="True" FontSize="0.01">
                    <Grid Margin="0,0,5,0">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="67"/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <StackPanel Grid.Column="0" Background="Transparent">
                            <Border Background="White" BorderThickness="0" Width="62" Height="62" HorizontalAlignment="Left" Margin="0,0,0,5">
                                <Image Source="{Binding image.thumbnail_link}" Width="62" Height="62"></Image>
                            </Border>
                        </StackPanel>
                        <StackPanel Grid.Column="1" VerticalAlignment="Center" Background="Transparent">
                            <!--<TextBlock Text="{Binding name}" HorizontalAlignment="Left" FontSize="30" VerticalAlignment="Center" Margin="0,0,0,5" />-->
                            <phone:LongListSelector x:Name="SpacesList"
                                        Background="Transparent"
                                        ItemTemplate="{StaticResource SpacesTemplate }" 
                                        ItemsSource="{Binding spaces}" 
                                        Margin="40,0,0,96" 
                                        LayoutMode="List"
                                        HideEmptyGroups="True"
                                        IsGroupingEnabled="False" VerticalContentAlignment="Top">
                            </phone:LongListSelector>
                        </StackPanel>
                    </Grid>
                </Button>
            </StackPanel>
        </DataTemplate>
        <DataTemplate x:Key="SpacesTemplate">
            <Border Background="Transparent" Padding="5,0,0,5">
                <Border Background="{StaticResource PhoneAccentBrush}" BorderBrush="{StaticResource PhoneAccentBrush}" BorderThickness="2" Width="62" 
         Height="62" Margin="0,0,18,0" HorizontalAlignment="Left">
                    <TextBlock Text="{Binding name}" Foreground="{StaticResource PhoneForegroundBrush}" FontSize="48" Padding="6" 
            FontFamily="{StaticResource PhoneFontFamilySemiLight}" HorizontalAlignment="Left" VerticalAlignment="Center"/>
                </Border>
            </Border>
        </DataTemplate>

在我的数据模板中,我放置了LongListselector ...它也需要一个模板。但是无法看到在当前数据模板之外定义的SpacesTemplate。任何想法如何从datatemplate“OrganisationsItemTemplate”中引用datatemplate“SpacesTemplate”

1 个答案:

答案 0 :(得分:1)

自上而下阅读

Xaml,如果您想在SpacesTemplate内使用OrganisationsItemTemplate,则必须在SpacesTemplate之前OrganisationsItemTemplate放置Xaml }}