按钮是图形用户界面中的简单元素,可以将鼠标点击或手指点击(在移动设备上)作为输入。
我在我的 WinUI3 应用程序中创建了一个自定义按钮组件。下面给出了相同的代码。 我在我的 WinUI3 应用程序中创建了一个自定义按钮组件。下面给出了相同的代码。 <Button HorizontalAlignment="Center" VerticalAlignment="Center" Background="Transparent" BorderThickness="0" Width="{x:Bind Width}" Height="{x:Bind Height}"> <StackPanel Orientation="Vertical" VerticalAlignment="Center" HorizontalAlignment="Center"> <FontIcon VerticalAlignment="Center" FontFamily="{StaticResource SymbolThemeFontFamily}" Glyph="{x:Bind Glyph}" FontSize="{x:Bind IconSize}" /> <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,10,0,0" Text="{x:Bind Label}" FontSize="{x:Bind FontSize}" /> </StackPanel> </Button> 默认情况下,它给出了一个非常浅的灰色背景,这在页面的白色背景中几乎不可见。所以我想在光标悬停在按钮上时或按钮通过选项卡处于焦点时更改按钮的背景颜色。 我怎样才能做到这一点? 我试过<ControlTemplate>,<VisualStateManager.VisualStateGroups><VisualState x:Name="PointerOver">和<Storybaord>但我无法让它工作。 我希望它有我选择的颜色,这样它更突出。就像默认的一样<AppBarButton> 正如您在 DefaultButtonStyle 中所见,VisualState PointerOver 将按钮的 Background 更改为名为 ButtonBackgroundPointerOver 的 ThemeResource。 (如果您不知道如何找到 generic.xaml,请查看此 answer。) 您可以像这样覆盖ButtonBackgroundPointerOver: <Button> <Button.Resources> <Button.Resources> <SolidColorBrush x:Key="ButtonBackgroundPointerOver" Color="HotPink" /> </Button.Resources> </Button.Resources> </Button> 不幸的是,Button 控件没有针对焦点事件的 VisualState。您可以做的是在代码隐藏中使用 Background 和 GotFocus 事件更改按钮的 LostFocus,但您也可以创建自定义控件: AwesomeButton.cs public class AwesomeButton : Button { public static readonly DependencyProperty FocusedBackgroundProperty = DependencyProperty.Register( nameof(FocusedBackground), typeof(Brush), typeof(AwesomeButton), new PropertyMetadata(default)); public AwesomeButton() { GotFocus += AwesomeButton_GotFocus; LostFocus += AwesomeButton_LostFocus; } public Brush FocusedBackground { get => (Brush)GetValue(FocusedBackgroundProperty); set => SetValue(FocusedBackgroundProperty, value); } private Brush? BackgroundBeforeGettingFocus { get; set; } private void AwesomeButton_GotFocus(object sender, RoutedEventArgs e) { BackgroundBeforeGettingFocus = Background; Background = FocusedBackground; } private void AwesomeButton_LostFocus(object sender, RoutedEventArgs e) { Background = BackgroundBeforeGettingFocus; } } 并像这样使用它: <local:AwesomeButton x:Name="AwesomeButton" Width="{x:Bind Width}" Height="{x:Bind Height}" HorizontalAlignment="Center" VerticalAlignment="Center" Background="Transparent" BorderThickness="0" FocusedBackground="LightGreen"> <Button.Resources> <SolidColorBrush x:Key="ButtonBackgroundPointerOver" Color="HotPink" /> </Button.Resources> <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Orientation="Vertical"> <FontIcon VerticalAlignment="Center" FontFamily="{StaticResource SymbolThemeFontFamily}" FontSize="{x:Bind IconSize}" Glyph="{x:Bind Glyph}" /> <TextBlock Margin="0,10,0,0" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="{x:Bind FontSize}" Text="{x:Bind Label}" /> </StackPanel> </local:AwesomeButton>
我有一个任务(javafx)想要制作单选按钮(上,下,右,左)并显示按钮,当您选择方向并单击显示时,第二阶段的矩形必须出现在直接.. .
我是python的新手。我通过条目小部件从用户那里获取值,当用户按下“添加”按钮时,该小部件将存储在列表中。稍后将使用列表的值 ...
我想使用我电脑中的自定义字体作为占位符和按钮。 我的@font-face。 @字体脸{ 字体系列:customfont2; src: url(字体/otf/segment14.regular.otf); } 我...
我想使用我电脑中的自定义字体作为占位符和按钮。 我的@font-face。 @字体脸{ 字体系列:customfont2; src: url(字体/otf/segment14.regular.otf); } 我...
我正在创建小的 html 离线页面,以在信息亭模式(没有互联网的小型博物馆)中作为文本面板显示在触摸屏上。我的背景图片是实际的滚动文本面板,我想...
我有一个 .php 脚本,可以计算按钮的点击次数并将它们放入 .txt 文件中,在这里一切都很好,但我现在只有一次计数。如果,比方说,我做了两个按钮,它会......
我正在学习如何编写代码。我得到了这段代码,但是在连接我的输入/input.value 的功能参数时遇到了问题。 我希望达到那种学习水平,我的意思是,我知道我不能使用...
当我在谷歌上进行研究时,我总是看到他们需要或使用一个按钮才能使 javascript 工作。但我需要的是一个不使用按钮的确认弹出框。就像当你运行代码时,
修复漂移的 Google Sheets Apps Script 图像按钮
我正在寻找可靠的资源而不仅仅是GPT幻觉...... 当我加载表格时,我试图让我的 Google 表格按钮留在一个地方。他们倾向于四处漂移或移动......
我有以下代码。有一些预先存在的代码,我在下面添加了新的更改。但是,我看到在我的按钮中,顶部和底部有一些填充。我不确定这是哪里...
Jquery next button function is not looped to the first slide once reached end
我创建了一个添加了下一个和上一个按钮的滑块。但是我遇到了一个我仍然无法弄清楚的问题。 单击下一个按钮,它会导航到下一个内容,但在
我正在尝试使用 PKPaymentButton 实现 applePayButton。 我声明它: 私有 var applePayBtn = PKPaymentButton.init(paymentButtonType:.plain,paymentButtonStyle:.black) 点击后...
我是 AS3 的新手,可以在单个 AS3 代码/框架中放置 2 个下一帧按钮这是我的代码,请帮忙谢谢 up1.addEventListener(MouseEvent.CLICK, gotoNextFrame); 函数 gotoNex...
如果我从下拉列表中选择一个值,我会在此处显示表格视图单元格中的下拉列表,我需要替换现有数组索引中的所选值 例如:我有这样的数组 数组前 ----- ...
在这里输入图片描述 尺寸框( 宽度:275, 孩子:ElevatedButton( 孩子:对齐( 对齐方式:Alignment.centerLeft, 孩子:文字( ' 登录', 文本对齐:文本对齐。正确的, ), ), onPressed: () {
背景 我有一个风险游戏学习项目的 MVVM 框架。我决定尝试以编程方式创建 UI 的一部分,既“方便”/优雅,又作为学习
有人可以教我如何从一个按钮访问 CometChatUserListWithMessages,该按钮重定向到我导入了 cometchat 的消息页面。 (cometchat 的行为就像我的页面中的一个小部件......
我有一个页面上有一堆按钮的视图。每个按钮都使用我添加到资产文件夹中的一本书的图像。在我的按钮上,我有一些关于 .onLongPressGesture 修饰符的代码,它将基于...
我的 regularBtn,regularBtn 在 tableview 单元格的视图中,就像这样在 tableview 中的故事板按钮设计层次结构中 和按钮代码:但是如果发件人==单元格,我就不能进去了?