首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TemplateBinding“前台”不起作用

TemplateBinding“前台”不起作用
EN

Stack Overflow用户
提问于 2009-08-19 15:14:14
回答 1查看 1.4K关注 0票数 4

我有一个列表框,它的项模板是一个列表框。我正在尝试将内部列表框的"Foreground“属性设置为与主列表框的属性相同。这是失败的。以下是代码片段。在这里前台“{TemplateBinding Foreground=}”没有效果。

代码语言:javascript
复制
<ListBox x:Name="GroupListBox" Grid.Column="1" Grid.Row="1" Style="{StaticResource ListBoxStyle1}" Visibility="Collapsed"
             BorderBrush="Transparent" Background="Transparent" Foreground="{Binding WebForeground}">
        <ListBox.ItemTemplate>
            <DataTemplate x:Name="test">
                <StackPanel Orientation="Horizontal" >
                    <!--<TextBlock Text="{Binding Rank}" FontFamily="Arial" FontSize="13" TextDecorations="Underline" TextWrapping="Wrap" Width="115" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,15,0,0"/>-->
                    <ListBox x:Name="SubGroupListBox" ItemsSource="{Binding InnerList }" ItemTemplate="{StaticResource ItemTemplateKey1}" 
                             ItemsPanel="{StaticResource ItemsPanelKey}" Style="{StaticResource ListBoxStyle1}" 
                             BorderBrush="Transparent" Background="Transparent" Foreground="{TemplateBinding Foreground}">                            
                    </ListBox>
             </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
EN

回答 1

Stack Overflow用户

发布于 2012-08-24 22:57:21

这个例子适用于我--它可能适用于你正在尝试做的事情:

代码语言:javascript
复制
    <ListBox x:Name="GroupListBox" Foreground="Purple">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal" >
                <ListBox Foreground="{Binding Foreground, RelativeSource={RelativeSource Self}}">
                    <TextBox Text="{Binding Mode=OneWay}" FontSize="35" Foreground="{Binding Foreground, RelativeSource={RelativeSource Self}}"  />
                </ListBox>
         </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>

    <ListBox.ItemsSource>
        <x:Array Type="{x:Type sys:String}">
            <sys:String>Sample Data</sys:String>
            </x:Array>
    </ListBox.ItemsSource>

</ListBox>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1300607

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档