- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在 avalonia 和大多数作品中尝试样式,除了伪类,它们只是被忽略了。
我创建了一个窗口,所有样式都在那里,我创建了一个用户控件(带有一个按钮 - 伪类在按钮上),使用样式。我不使用代码,只使用 xaml 来定义样式。
我已经在“样式选择器”中将按钮作为“Button:pseudoclassname”和“Button.le:pseudoclassname”进行了尝试。我也尝试过“Button:pointerover”和“Button:hover”,因为文档提到可以修改。没有结果。伪类的样式全部被忽略,其他的都正确执行。
是我做错了什么还是 avalonia 中的错误?
xaml 窗口文件:
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:views="clr-namespace:Hub.Views"
xmlns:vm="using:Hub.ViewModels"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Hub.Views.MainWindow"
Icon="/Assets/avalonia-logo.ico"
Width="200" Height="300"
Title="Hub"
Classes="le">
<Window.Styles>
<Style Selector="Window.le">
<Setter Property="Background" Value="#191919"/>
</Style>
<Style Selector="Button.le">
<Setter Property="Background" Value="green"/>
<Setter Property="Foreground" Value="white"/>
</Style>
<Style Selector="Button.le:pointerover">
<Setter Property="Background" Value="red"/>
<Setter Property="Foreground" Value="white"/>
</Style>
<Style Selector="Button.le:pressed">
<Setter Property="Background" Value="blue"/>
<Setter Property="Foreground" Value="white"/>
</Style>
<Style Selector="TextBlock.le_update">
<Setter Property="FontStyle" Value="Italic"/>
<Setter Property="FontSize" Value="17"/>
<Setter Property="FontFamily" Value="Arial, Verdana"/>
<Setter Property="Foreground" Value="white"/>
<Setter Property="Background" Value="transparent"/>
</Style>
</Window.Styles>
<views:UpdateView/>
</Window>
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Hub.Views.UpdateView">
<DockPanel>
<StackPanel DockPanel.Dock="Bottom">
<Button Classes="le" HorizontalAlignment="Center" HorizontalContentAlignment="Center" Width="300">
Check for updates
</Button>
</StackPanel>
<StackPanel Spacing="5" Margin="5">
<TextBlock Classes="le_update" HorizontalAlignment="Center" Margin="4">
No updates for Hub.
</TextBlock>
<TextBlock Classes="le_update" HorizontalAlignment="Center" Margin="4">
No updates for Engine.
</TextBlock>
</StackPanel>
</DockPanel>
</UserControl>
最佳答案
Button
的 Background
属性确实会受到您的风格的影响,但此时它对实际 Button
没有影响。的背景,因为 Background
属性仅控制按钮的正常状态。
如果你看一下默认的 Button
款式here你可以看到它把它的背景传给了 ContentPresenter
通过 TemplateBinding
:
<Setter Property="Template">
<ControlTemplate>
<ContentPresenter x:Name="PART_ContentPresenter"
Background="{TemplateBinding Background}"
但以如下样式覆盖 ContentPresenter 的背景:
<Style Selector="Button:pointerover /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Background" Value="{DynamicResource ButtonBackgroundPointerOver}" />
既然是
ContentPresenter
实际上绘制背景(
Button
是一个无外观的控件),你会看到按钮有
ButtonBackgroundPointerOver
而不是
Button
的
Background
适当的值(value)。
<Style Selector="Button.le:pointerover /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Background" Value="green" />
</Style>
不幸的是,这使您的样式依赖于主题,因为默认主题和流畅主题之间的控件模板不同。
关于xaml - AvaloniaUI 样式-伪类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66442508/
我一直在尝试各种技术来尝试让按钮标签文本居中对齐。当我查看 Avalonia DevTools inpspector 中的按钮时,我可以看到 AccessText TextAlignment 始终设置
我正在使用 AvaloniaUI 并尝试实现:http://avaloniaui.net/api/Avalonia.Controls/OpenFolderDialog/ 我想要实现的是,当我按下一个按
每当我尝试重新启动 Avalonia 应用程序表单基础应用程序时,我都会收到一个异常:“已在其中一个 AppBuilder 实例上调用了安装程序。”在 SetupWithLifetime() 调用上。
我正在 avalonia 和大多数作品中尝试样式,除了伪类,它们只是被忽略了。 我创建了一个窗口,所有样式都在那里,我创建了一个用户控件(带有一个按钮 - 伪类在按钮上),使用样式。我不使用代码,只使
在 GDI+ 中,可以直接在 Canvas 上绘图(创建一个内存位图并在那里做任何需要做的事情)。 对于 Avalonia,我需要相同的“自定义控件”,我被告知这是可能的,因为可以访问 SkiaSha
我正在玩 Avalonia我正在尝试显示一个消息框,该消息框等同于 WinForms 的 MessageBox.Show()。我找到了 GitHub issue那是为此请求一个 API,但我想知道人们
如果在WPF中一个装饰元素是使用抽象类Adorner实现的,那么在Avalonia UI中如何实现这个对象呢? //code wpf public class ControlAdorn
我是一名优秀的程序员,十分优秀!