【问题标题】:TemplateBinding "Foreground" doesn't workTemplateBinding“前景”不起作用
【发布时间】:2009-08-19 15:14:14
【问题描述】:

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

<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>

【问题讨论】:

    标签: templatebinding


    【解决方案1】:

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

        <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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-05
      • 2016-05-22
      • 2021-12-19
      相关资源
      最近更新 更多