问题描述
我尝试制作一个简单的 C# UWP 应用程序,但当我的鼠标悬停在按钮上时,我不知道如何移除灰色背景.
我该怎么做?
(记住:它是适用于 Windows 10 平台的 UWP,而不是 Windows Phone 8.1 或 WPF)
请按以下步骤操作:
- 在解决方案资源管理器中单击鼠标右键并添加一个新项目ResourceDictionary"
- 复制按钮的默认样式你可以在这个网页上找到它,你需要向下滚动一点:
如果您使用 Blend for Visual Studio 有一个更简单的解决方案,您可以更快地编辑这些内容,但要保持结构并学习它,上面的解决方案是更好的解决方案.
I've tried to make a simple C# UWP application and I don't know how to remove the gray background when my mouse is over the button.
How I do that?
(remember: it's an UWP for Windows 10 platform , not Windows Phone 8.1 or WPF)
Follow these steps:
- Rightclick in the Solution Explorer and add a new item of kind "ResourceDictionary"
- Copy the Default Style of the Button you can find it on this webpage, you need to scroll down a little bit: Msdn
Then insert it in your ResourceDictionary.xaml format should look like this:
<ResourceDictionary><Style></Style></ResourceDictionary>
3. Give the Style a key like this:
<Style x:Key="MyCustomButton"></Style>
4. Go to App.xaml edit it by adding the Resource Dictionary like this:
<Application.Resources>
<ResourceDictionary Source="Resources.xaml"></ResourceDictionary>
</Application.Resources>
The Source of the ResourceDictionary is the Name of your ResourceDictionary file.
- Then add the style to your button like this:
<Button Style="{StaticResource MyCustomButton}"></Button>
- Last but not least go back to your ResourceDictionary and delete the following code lines you see in the Screenshot or comment it out like i did:
There is a more easy solution if you use Blend for Visual Studio there you can edit this stuff more quickly but to keep the structure and for learning it the solution above is the better one.
这篇关于在通用 Windows 平台中更改按钮样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!