我有一个ListBox
带按钮的DataTemplate
。ListBox
视图项位于 s 列表中ToggleButton
。
我的问题是如图所示的选定项目背景:
如图所示,问题出在按钮一上。此屏幕截图是在首次加载 wpf 页面时拍摄的(在选中切换按钮之前)。如果我然后检查切换按钮(按钮一),边框中的白色将消失
我不希望显示这种白色(如两个按钮)。我有:
<ListBox x:Name="lbname" ItemsSource="{Binding myCollection}" Margin="432,110,0,158" Width="214" HorizontalAlignment="Left" Background="{x:Null}" BorderBrush="{x:Null}">
<ListBox.Resources>
<Style TargetType="ListBoxItem">
<Style.Resources>
<!-- SelectedItem with focus -->
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
Color="Transparent" />
<!-- SelectedItem without focus -->
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}"
Color="Transparent" />
<!-- SelectedItem text foreground -->
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}"
Color="Black" />
</Style.Resources>
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
</Style>
</ListBox.Resources>
<ListBox.ItemTemplate>
<DataTemplate>
<ToggleButton x:Name="btnname" tyle="{StaticResource ToggleStyle}" FontFamily="tahoma" FontSize="14" Height="55" Width="208" FontWeight="Normal" IsChecked="{Binding IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}}" Background="{x:Null}" BorderBrush="{x:Null}" Checked="btnname_Checked" >
<Grid>
<Image Height="55" Width="205">
<Image.Style>
<Style>
<Setter Property="Image.Source" Value="/myApplication;component/images/buttons/two.png" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}}" Value="True">
<Setter Property="Image.Source" Value="/myApplication;component/images/buttons/one.png" />
</DataTrigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>
<TextBlock Text="{Binding Name}" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
</ToggleButton>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
对于如何解决这个问题,有任何的建议吗?