listbox选中后背景颜色设定

yukiwa 2009-03-25 11:29:09
用listbox自定义了一个radiobuttonlist,但是在选择时如果正好选在listbox和radiobutton之间的部分就会出现Listboxitem选中的背景色,参考了一trigger,但是还是无法设置背景色,想问一下问题在哪里

<UserControl x:Class="WpfApplication1.RadioButtonList"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300">
<Grid>
<StackPanel Margin="0,0,21.658,0" Height="44" VerticalAlignment="Top">
<StackPanel.Resources>
<Style x:Key="HorizontalRadioButtonList" TargetType="{x:Type ListBox}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<VirtualizingStackPanel Background="Transparent" Orientation="Horizontal"/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<RadioButton Name="radioitem">
<ContentPresenter/>
</RadioButton>
<ControlTemplate.Triggers>
<Trigger Property="IsFocused" Value="false">
<Setter TargetName="radioitem" Property="Background" Value ="Black" />
<Setter TargetName="radioitem" Property="Opacity" Value="0.5" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBox}">
<Border BorderThickness="0" Padding="0" BorderBrush="Transparent" Background="Transparent" Name="Bd" SnapsToDevicePixels="True">
<ItemsPresenter SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</StackPanel.Resources>


<ListBox Name="windowStyleSelector" Style="{StaticResource HorizontalRadioButtonList}" >
<ListBoxItem >
<Label >aa</Label>
</ListBoxItem>
</ListBox>
</StackPanel>
</Grid>
</UserControl>
...全文
222 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
xp25369 2011-05-05
  • 打赏
  • 举报
回复
我碰到这个问题,一直不知道为什么

17,740

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 .NET Framework
社区管理员
  • .NET Framework社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧