简体   繁体   English

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

[英]Change button style in Universal Windows Platform

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. 我试图制作一个简单的C#UWP应用程序,当鼠标悬停在按钮上时,我不知道如何删除灰色背景。

How I do that? 我怎么做的?

(remember: it's an UWP for Windows 10 platform , not Windows Phone 8.1 or WPF) (记住:它是适用于Windows 10平台的UWP,而不是Windows Phone 8.1或WPF)

简单的按钮

我的鼠标结束时按钮

Follow these steps: 跟着这些步骤:

  1. Rightclick in the Solution Explorer and add a new item of kind "ResourceDictionary" 在解决方案资源管理器中右键单击并添加一个新的“ResourceDictionary”项
  2. Copy the Default Style of the Button you can find it on this webpage, you need to scroll down a little bit: Msdn 复制你可以在这个网页上找到的按钮的默认样式,你需要向下滚动一点: Msdn

Then insert it in your ResourceDictionary.xaml format should look like this: 然后将它插入您的ResourceDictionary.xaml格式应如下所示:

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

3. Give the Style a key like this: 3.给Style一个这样的键:

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

4. Go to App.xaml edit it by adding the Resource Dictionary like this: 4.转到App.xaml,通过添加资源字典来编辑它,如下所示:

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

The Source of the ResourceDictionary is the Name of your ResourceDictionary file. ResourceDictionary的Source是ResourceDictionary文件的名称。

  1. Then add the style to your button like this: <Button Style="{StaticResource MyCustomButton}"></Button> 然后将样式添加到按钮,如下所示: <Button Style="{StaticResource MyCustomButton}"></Button>
  2. 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: 最后但并非最不重要的是回到您的ResourceDictionary并删除您在屏幕截图中看到的以下代码行,或者像我一样注释掉它: 编辑你的风格

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. 有一个更简单的解决方案,如果你使用Blend for Visual Studio,你可以更快地编辑这些东西,但为了保持结构和学习它,上面的解决方案是更好的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM