c# - 在通用 Windows 平台中更改按钮样式

标签 c# windows windows-10 win-universal-app

我尝试制作一个简单的 C# UWP 应用程序,但我不知道如何在鼠标悬停在按钮上时删除灰色背景。

我该怎么做?

(记住:它是 Windows 10 平台的 UWP,不是 Windows Phone 8.1 或 WPF)

The simple button

the button when my mouse is over

最佳答案

请按照以下步骤操作:

  1. 在 Solution Explorer 中右键单击并添加一个新的项目“ResourceDictionary”
  2. 复制按钮的默认样式你可以在这个网页上找到它,你需要向下滚动一点: Msdn

然后以您的 ResourceDictionary.xaml 格式插入它应该如下所示:

<ResourceDictionary><Style></Style></ResourceDictionary>

3。像这样给样式一个键:

<Style x:Key="MyCustomButton"></Style>

4.转到 App.xaml 通过添加 Resource Dictionary 对其进行编辑,如下所示:

<Application.Resources>
    <ResourceDictionary Source="Resources.xaml"></ResourceDictionary>
</Application.Resources>

ResourceDictionary 的来源是您的 ResourceDictionary 文件的名称。

  1. 然后像这样将样式添加到您的按钮:<Button Style="{StaticResource MyCustomButton}"></Button>
  2. 最后但同样重要的是返回到您的 ResourceDictionary 并删除您在屏幕截图中看到的以下代码行,或者像我一样将其注释掉: Edit your style

如果您使用 Blend for Visual Studio,则有一个更简单的解决方案,您可以更快地编辑这些东西,但为了保持结构和学习它,上面的解决方案是更好的解决方案。

关于c# - 在通用 Windows 平台中更改按钮样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32920211/

相关文章:

c# - 如何使用 View Model 实现代码隐藏功能?

c# - 如何停止 XDocument.Save 写入转义字符

c++ - 从 Visual Studio 2017 运行 CMake 的 PACKAGE 目标

powershell - 找不到证书 : drive or Certificate Provider via Powershell

python - 对于嵌入式 Python,前缀 PYTHONPATH 不在 sys.path 中

Powershell 5.0/Windows 10 Get-Command 空引用异常

c# - 在继承类中使用自定义枚举覆盖枚举

c# - StackExchange RedisValue ToByteArray 不可序列化

c - window OS下c中的包嗅探

Windows:从 CMD 返回值以存储为变量