Change button style in Universal Windows Platform

空扰寡人 提交于 2019-12-13 11:36:00

问题


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)


回答1:


Follow these steps:

  1. Rightclick in the Solution Explorer and add a new item of kind "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

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.

  1. Then add the style to your button like this: <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:

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.



来源:https://stackoverflow.com/questions/32920211/change-button-style-in-universal-windows-platform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!