【问题标题】:How to reference a static resource from within a datatemplate如何从数据模板中引用静态资源
【发布时间】:2013-10-17 22:52:21
【问题描述】:

我有以下问题:

<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。任何想法如何从数据模板“OrganisationsItemTemplate”中引用数据模板“SpacesTemplate”

【问题讨论】:

  • 啊,抱歉。我认为这很好用..实际上是列表泄漏了手机的边界..我没有阅读错误...或者没有。以上看起来是对还是错?很难说是不是错误?
  • Xaml 是自上而下读取的,如果你想在 OrganisationsItemTemplate 中使用 SpacesTemplate,你必须在 Xaml 中将 SpacesTemplate 放在 OrganisationsItemTemplate 之前
  • 这就是答案。好家伙。很高兴最后没有删除我的问题!很酷,谢谢!

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


【解决方案1】:

Xaml 是自上而下阅读的,如果你想在OrganisationsItemTemplate 中使用SpacesTemplate,你必须在OrganisationsItemTemplate 之前将SpacesTemplate 放在Xaml

【讨论】:

  • 旁注,数据下钻好吗?如果我的父数据模板正在使用“Organisations”并访问其中的名称属性..如果我在第二个 LongListSelector 中将数据源作为空格...这将访问 Organizations 对象内的空格列表,这是一个列表其中有“名称”属性。听起来不错不是吗...只是我的跳转列表似乎变平了,我猜是因为它没有数据可以将位向下推。
猜你喜欢
  • 2019-03-15
  • 1970-01-01
  • 2015-01-05
  • 2014-04-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多