WPF 样式

来源:互联网 发布:小米2s怎么用3g网络 编辑:程序博客网 时间:2024/05/01 14:13

1、定义 资源字典


<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">    <RadialGradientBrush x:Key="mybrush">        <GradientStop Color="#FF0000" Offset="0"/>        <GradientStop Color="#00ff00" Offset="1"/>        <GradientStop Color="#0000ff" Offset="0.6669"/>    </RadialGradientBrush></ResourceDictionary>

2、引用 资源字典

<!--定义应用程序对象--><Application x:Class="WpfApplication1.App"             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"             StartupUri="Window5.xaml" Exit="AppExit">    <!--StartupUri 启动时,显示那个xaml-->    <x:Code>        <![CDATA[            private void AppExit(object sender,ExitEventArgs e)            {                MessageBox.Show("App has Exit!");            }        ]]>    </x:Code>             <Application.Resources>        <ResourceDictionary>            <ResourceDictionary.MergedDictionaries>                                            <!--外部库名称;Component/编译的二进制资源名称-->                <ResourceDictionary Source="/MyBrushesLibrary;Component/MyBrushes.xaml"/>                <ResourceDictionary Source="......"/>             </ResourceDictionary.MergedDictionaries>         </ResourceDictionary>      </Application.Resources> </Application>



3、应用

<Window x:Class="WpfApplication1.Window5"        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"        Title="Window5" Height="300" Width="300">    <StackPanel Orientation="Vertical">        <Button Width="204" Height="73" Content="OK" x:Name="BtnOK" Background="{DynamicResource myBrush}"  Click="BtnOK_Click"></Button>        <Button Width="204" Height="73" Content="Cancel" x:Name="BtnName2" Background="{StaticResource myBrush}"/>    </StackPanel></Window>


0 0
原创粉丝点击