TemplateBinding“前景” 不起作用
我有一个列表框,其项目模板是一个列表框。 我试图将内部列表框的“前景”属性设置为与主列表框的“前景”属性相同。 这是失败的。 以下是代码片段。 在这里 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>
I have a listbox the item template of which is a listbox. I am trying to set the "Foreground" property of the internal listbox to be the same as that of the main listbox. This is failing. Following is the code snippet. In here Foreground="{TemplateBinding Foreground}" has no effect.
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个例子对我有用 - 它可能适用于你想要做的事情:
This example works for me - it may apply to what you are trying to do: