WPF中ListBoxItem控件模板设计的问题?
这是我的XAML:WPF中ListBoxItem控件模板设计的问题?,wpf,wpf-controls,controltemplate,Wpf,Wpf Controls,Controltemplate,这是我的XAML: <ListBox Name="PlaylistListBox" ScrollViewer.CanContentScroll="False" HorizontalContentAlignment="Stretch" ItemsSource="{Binding Source={StaticResource ResourceKey=MyListBoxView}}" ItemTemplateSelector="{Binding Source={St
<ListBox
Name="PlaylistListBox"
ScrollViewer.CanContentScroll="False"
HorizontalContentAlignment="Stretch"
ItemsSource="{Binding Source={StaticResource ResourceKey=MyListBoxView}}"
ItemTemplateSelector="{Binding Source={StaticResource ResourceKey=MySelector}}"
MouseDoubleClick="PlaylistListBox_MouseDoubleClick" >
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border
Name="Border"
CornerRadius="4"
SnapsToDevicePixels="true">
<ContentPresenter />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter TargetName="Border" Property="Background" Value="Black" />
<!-- The following setter for opacity is giving me headaches -->
<Setter TargetName="Border" Property="Opacity" Value="0.5" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<EventSetter
Event="Loaded"
Handler="PlaylistListBoxItem_Loaded" />
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
两个问题:
不透明度
设置器,整个项目的透明度为50%。我只想要一个
ListBoxItem
ControlTemplate
中定义的边框及其内容是透明的
以保持完全不透明度李>
列表框
不可用时,如何使Setter/Trigger使相同的边框变为红色
聚焦?它应该类似于InFocus=“False”
和IsSelected=“True”
李>
谢谢你的澄清
网格
并首先在其中放置一个“背景”边框,然后再放置内容来完成此操作。这样,您将只在背景边框上设置不透明度,而不在内容上设置不透明度multi-trigger
<ListBox
Name="PlaylistListBox"
ScrollViewer.CanContentScroll="False"
HorizontalContentAlignment="Stretch"
ItemsSource="{Binding Source={StaticResource ResourceKey=MyListBoxView}}"
ItemTemplateSelector="{Binding Source={StaticResource ResourceKey=MySelector}}"
MouseDoubleClick="PlaylistListBox_MouseDoubleClick" >
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Grid>
<Border
Name="BackgroundBorder"
CornerRadius="4"
SnapsToDevicePixels="true">
</Border>
<Border Name="Border">
<ContentPresenter />
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter TargetName="BackgroundBorder" Property="Background" Value="Black" />
<!-- The following setter for opacity is giving me headaches -->
<Setter TargetName="BackgroundBorder" Property="Opacity" Value="0.5" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="True"/>
<Condition Property="IsFocused" Value="False"/>
</MultiTrigger.Conditions>
<Setter TargetName="BackgroundBorder" Property="Background" Value="Red" />
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<EventSetter
Event="Loaded"
Handler="PlaylistListBoxItem_Loaded" />
</Style>
</ListBox.ItemContainerStyle>
</ListBox>