WPF改变颜色问题

wozhaozhe2008 2020-06-30 04:03:31
WPF有没有什么好办法改变选中颜色,比方说一个BUTTON按钮,我移入改变颜色,除了Template外还有什么办法吗?
因为用模板的话就什么都需要自己去实现了,玩仅仅只是改变个选中颜色而已。
当然Button按钮没什么,但其他复杂一点的比方说Listview。就仅仅改变个选中颜色值,
接连其他的功能全部都需要自己再去实现一遍
...全文
3370 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
wozhaozhe2008 2020-07-01
  • 打赏
  • 举报
回复
引用 6 楼 icoolno1 的回复:
定义VisualState即可。
我百度搜下,谢谢!
鸡窝里的毛 2020-07-01
  • 打赏
  • 举报
回复
定义VisualState即可。
鸡窝里的毛 2020-07-01
  • 打赏
  • 举报
回复
引用 楼主 wozhaozhe2008的回复:
WPF有没有什么好办法改变选中颜色,比方说一个BUTTON按钮,我移入改变颜色,除了Template外还有什么办法吗?
因为用模板的话就什么都需要自己去实现了,玩仅仅只是改变个选中颜色而已。
当然Button按钮没什么,但其他复杂一点的比方说Listview。就仅仅改变个选中颜色值,
接连其他的功能全部都需要自己再去实现一遍
事件触发器,属性触发器,再不济直接处理事件。
wozhaozhe2008 2020-07-01
  • 打赏
  • 举报
回复
引用 4 楼 独立观察员 的回复:
可以用样式触发器吧
这个是数据触发器:
WPF 让一组 Button 实现 RadioButton 的当前样式效果》(http://dlgcy.com/wpf-button-as-radiobutton/)

你这个要求应该是用事件触发器
好的,我去查下资料看看,谢谢!
wozhaozhe2008 2020-07-01
  • 打赏
  • 举报
回复
引用 9 楼 icoolno1 的回复:
[quote=引用 8 楼 wozhaozhe2008 的回复:][quote=引用 6 楼 icoolno1 的回复:]定义VisualState即可。
网上就找到一个,还直接给了一段代码,连为什么都没说,能简单的说下这怎么用吗?[/quote] 每个控件都有自己的VisualState,可以根据这个东西来定义每个VisualState的外观。比如按钮的VisualState有这些: VisualState Name VisualStateGroup Name Description Normal CommonStates The default state. MouseOver CommonStates The mouse pointer is positioned over the control. Pressed CommonStates The control is pressed. Disabled CommonStates The control is disabled. Focused FocusStates The control has focus. Unfocused FocusStates The control does not have focus. Valid ValidationStates The control uses the Validation class and the HasError attached property is false. InvalidFocused ValidationStates The HasError attached property is true and the control has focus. InvalidUnfocused ValidationStates The HasError attached property is true and the control does not have focus.

<ControlTemplate x:Key="roundbutton" TargetType="Button">
    <Grid>
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup Name="CommonStates">
                <VisualState Name="Normal">
                </VisualState>
                <VisualState Name="MouseOver">
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        <Ellipse x:Name="backgroundElement" Fill="{TemplateBinding Background}" Stroke="{TemplateBinding Foreground}" />
        <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
    </Grid>
</ControlTemplate>
[/quote] 一样的,如果不用Template也不会变色,不过还是谢谢了!
独立观察员 2020-07-01
  • 打赏
  • 举报
回复
可以用样式触发器吧
这个是数据触发器:
WPF 让一组 Button 实现 RadioButton 的当前样式效果》(http://dlgcy.com/wpf-button-as-radiobutton/)

你这个要求应该是用事件触发器
鸡窝里的毛 2020-07-01
  • 打赏
  • 举报
回复
引用 8 楼 wozhaozhe2008 的回复:
[quote=引用 6 楼 icoolno1 的回复:]定义VisualState即可。

网上就找到一个,还直接给了一段代码,连为什么都没说,能简单的说下这怎么用吗?[/quote]

每个控件都有自己的VisualState,可以根据这个东西来定义每个VisualState的外观。比如按钮的VisualState有这些:

VisualState Name VisualStateGroup Name Description
Normal CommonStates The default state.
MouseOver CommonStates The mouse pointer is positioned over the control.
Pressed CommonStates The control is pressed.
Disabled CommonStates The control is disabled.
Focused FocusStates The control has focus.
Unfocused FocusStates The control does not have focus.
Valid ValidationStates The control uses the Validation class and the HasError attached property is false.
InvalidFocused ValidationStates The HasError attached property is true and the control has focus.
InvalidUnfocused ValidationStates The HasError attached property is true and the control does not have focus.


<ControlTemplate x:Key="roundbutton" TargetType="Button">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup Name="CommonStates">
<VisualState Name="Normal">
</VisualState>
<VisualState Name="MouseOver">
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Ellipse x:Name="backgroundElement" Fill="{TemplateBinding Background}" Stroke="{TemplateBinding Foreground}" />
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
</ControlTemplate>
wozhaozhe2008 2020-07-01
  • 打赏
  • 举报
回复
引用 6 楼 icoolno1 的回复:
定义VisualState即可。
网上就找到一个,还直接给了一段代码,连为什么都没说,能简单的说下这怎么用吗?
wozhaozhe2008 2020-06-30
  • 打赏
  • 举报
回复
引用 1 楼 以专业开发人员为伍 的回复:
ListView的“选中颜色值”是指什么值?Button的“选中颜色值”呢?其它控件呢?请贴出4、5个例子来了解一下问题。
还是拿button来举例,我用template改变了背景色,那么我就需要去实现按下的颜色,当然button简单,只需要多加一个条件去实现按下背景色,但listview就要实现太多的功能了。
wozhaozhe2008 2020-06-30
  • 打赏
  • 举报
回复
引用 1 楼 以专业开发人员为伍 的回复:
ListView的“选中颜色值”是指什么值?Button的“选中颜色值”呢?其它控件呢?请贴出4、5个例子来了解一下问题。
就是鼠标移入button控件,改变button背景颜色,用style是没效果的,只能用template。同理,listview也一样。
  • 打赏
  • 举报
回复
ListView的“选中颜色值”是指什么值?Button的“选中颜色值”呢?其它控件呢?请贴出4、5个例子来了解一下问题。
内容概要:SSD2828QN4是一款MIPI主桥接芯片,用于连接应用处理器与传统并行LCD接口及支持MIPI从属接口的LCD驱动器。该芯片支持最高每通道1Gbps的串行链路速度,最多可配置4个数据通道,显著减少了信号数量。它支持多种接口模式,包括RGB+SPI组合接口,适用于驱动智能或非智能显示面板,并能通过命令模式和视频模式传输数据。芯片内置时钟和复位模块、外部接口、协议控制单元(PCU)、包处理单元(PPU)、错误校正码/循环冗余校验(ECC/CRC)模块、长包和命令缓冲区、D-PHY控制器、模拟收发器以及内部锁相环(PLL),确保了高效的数据传输和系统稳定性。此外,文档详细描述了芯片的引脚分配、寄存器设置、操作模式、电源序列、时序特性等关键参数,为开发者提供了全面的技术指导。 适合人群:具备一定硬件设计基础,从事嵌入式系统开发、显示技术研究的研发人员。 使用场景及目标:①实现应用处理器与MIPI兼容显示屏之间的高速数据传输;②优化显示系统的功耗表现,减少电磁干扰(EMI);③通过灵活配置不同接口模式来适应各种显示设备的需求。 阅读建议:此文档面向具有一定电子工程背景的专业人士,建议读者结合实际项目需求深入理解各章节内容,特别是关于寄存器配置、时序要求等方面的具体说明。对于初次接触此类技术的开发者而言,建议先熟悉基本概念再逐步掌握高级功能的应用方法。

111,129

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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