控件有默认样式,但是有时候默认样式并不够用,就需要美化。
1、常用的方法是美术出图,直接贴图进去,效果又好又简单(对程序来说)。
用图片有三种方式:设置控件背景图片、设置控件内容为图片和直接使用图片做控件三种。
<Window x:Class="战五渣之环游世界.WPF.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:战五渣之环游世界.WPF" mc:Ignorable="d" Title="Window1" Height="450" Width="800"> <!--方案一,设置控件的背景为图片--> <Window.Background> <ImageBrush ImageSource="/images/mainbg.jpg"></ImageBrush> </Window.Background> <Grid> <Button> <!--方案二,设置控件的内容为图片,这里不能使用背景图片,因为按钮默认具有鼠标经过样式--> <Image Source="/images/mainbg.jpg"></Image> </Button> </Grid> </Window>