如何更改ListBox项的SelectedItem前景文本

 止在雲端_495 发布于 2023-02-13 20:47
  • php
  • 1 个回答
    • 您必须编辑ItemContainerStyle(编辑其他模板>编辑生成的项目容器(ItemContainerStyle)).

      内部ItemContainerStyleSelected视觉状态,您可以更改它.

      <Style x:Key="ListBoxItemStyle1" TargetType="ListBoxItem">
          <Setter Property="Background" Value="Transparent"/>
          <Setter Property="BorderThickness" Value="0"/>
          <Setter Property="BorderBrush" Value="Transparent"/>
          <Setter Property="Padding" Value="0"/>
          <Setter Property="HorizontalContentAlignment" Value="Left"/>
          <Setter Property="VerticalContentAlignment" Value="Top"/>
          <Setter Property="Template">
              <Setter.Value>
                  <ControlTemplate TargetType="ListBoxItem">
                      <Border x:Name="LayoutRoot" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}">
                          <VisualStateManager.VisualStateGroups>
                              <VisualStateGroup x:Name="CommonStates">
                                  <VisualState x:Name="Normal"/>
                                  <VisualState x:Name="MouseOver"/>
                                  <VisualState x:Name="Disabled">
                                      <Storyboard>
                                          <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="LayoutRoot">
                                              <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource TransparentBrush}"/>
                                          </ObjectAnimationUsingKeyFrames>
                                          <DoubleAnimation Duration="0" To=".5" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="ContentContainer"/>
                                      </Storyboard>
                                  </VisualState>
                              </VisualStateGroup>
                              <VisualStateGroup x:Name="SelectionStates">
                                  <VisualState x:Name="Unselected"/>
                                  <VisualState x:Name="Selected">
                                      <Storyboard>
                                          <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentContainer">
                                              <DiscreteObjectKeyFrame KeyTime="0" Value="YOUR_NEW_COLOR"/>
                                          </ObjectAnimationUsingKeyFrames>
                                      </Storyboard>
                                  </VisualState>
                              </VisualStateGroup>
                          </VisualStateManager.VisualStateGroups>
                          <ContentControl x:Name="ContentContainer" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Foreground="{TemplateBinding Foreground}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
                      </Border>
                  </ControlTemplate>
              </Setter.Value>
          </Setter>
      </Style>
      

      2023-02-13 20:51 回答
    撰写答案
    今天,你开发时遇到什么问题呢?
    立即提问
    热门标签
    PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
    Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有