在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例桌面应用界面/GUI → WPF 自定义window 风格 示例源码下载

WPF 自定义window 风格 示例源码下载

桌面应用界面/GUI

下载此实例
  • 开发语言:C#
  • 实例大小:0.08M
  • 下载次数:39
  • 浏览次数:775
  • 发布时间:2013-10-05
  • 实例类别:桌面应用界面/GUI
  • 发 布 人:crazycode
  • 文件格式:.rar
  • 所需积分:2
 相关标签: wpf

实例介绍

【实例简介】

【实例截图】

【核心代码】

<ResourceDictionary 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" mc:Ignorable="d" xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Luna">
   
    <ControlTemplate x:Key="WindowTemplateKey" TargetType="{x:Type Window}">
        <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
            <Grid>
                <AdornerDecorator>
                    <ContentPresenter/>
                </AdornerDecorator>
                <ResizeGrip x:Name="WindowResizeGrip" HorizontalAlignment="Right" VerticalAlignment="Bottom" IsTabStop="false" Visibility="Collapsed"/>
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="ResizeMode" Value="CanResizeWithGrip"/>
                    <Condition Property="WindowState" Value="Normal"/>
                </MultiTrigger.Conditions>
                <Setter Property="Visibility" TargetName="WindowResizeGrip" Value="Visible"/>
            </MultiTrigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ControlTemplate x:Key="CustomWindowControlTemplate"  TargetType="{x:Type Window}">
        <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="10,10,0,0" d:DesignHeight="106.166" d:DesignWidth="565.541">
            <Grid Width="Auto" Height="Auto" VerticalAlignment="Stretch">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="29.333"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <Border x:Name="topborder" Margin="0" Grid.Column="0" BorderBrush="{x:Null}" BorderThickness="0" CornerRadius="10,10,0,0" Grid.ColumnSpan="1">
                    <Border.Background>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FF343434" Offset="1"/>
                            <GradientStop Color="#FF8A8A8A"/>
                        </LinearGradientBrush>
                    </Border.Background>
                    <Grid HorizontalAlignment="Stretch" Margin="0" VerticalAlignment="Stretch" Width="Auto" Height="Auto">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="9.27"/>
                            <ColumnDefinition Width="137.397"/>
                            <ColumnDefinition/>
                            <ColumnDefinition Width="28.207"/>
                            <ColumnDefinition Width="30.016"/>
                            <ColumnDefinition Width="27.398"/>
                            <ColumnDefinition Width="7.586"/>
                        </Grid.ColumnDefinitions>
                        <TextBlock Margin="5.332,8,0,7.646" Grid.Column="1" Text="CustomWindow" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Center" Width="122.064" FontFamily="微软雅黑" Height="22.762" FontSize="14.667" FontWeight="Bold" Foreground="White"/>
                        <Button x:Name="btnMin" Margin="2.668,2.795,2.777,3.776" Content="-" Grid.Column="3" FontWeight="Bold" FontSize="16"/>
                        <Button x:Name="btnMax" Margin="3.891,2.795,3.363,3.776" Content="□" FontWeight="Bold" Grid.Column="4" FontSize="16"/>
                        <Button x:Name="btnClose" Margin="2.668,2.795,1.968,3.776" Content="×" FontWeight="Bold" Grid.Column="5" Style="{DynamicResource CloseButtonStyle}" Foreground="Black" FontSize="16"/>
                    </Grid>
                </Border>
                <Grid Margin="0" Grid.Row="1">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <ContentPresenter HorizontalAlignment="Stretch" Margin="0" Width="Auto" Grid.Column="0" Grid.ColumnSpan="1" Grid.RowSpan="1"/>
                </Grid>
            </Grid>
        </Border>
    </ControlTemplate>
        
    <Style x:Key="CustomWindowStyle" TargetType="{x:Type Window}">
		<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/>
		<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
		<Setter Property="Template" Value="{StaticResource CustomWindowControlTemplate}"/>
        <Style.Triggers>
			<Trigger Property="ResizeMode" Value="CanResizeWithGrip">
				<Setter Property="Template" Value="{StaticResource WindowTemplateKey}"/>
			</Trigger>
		</Style.Triggers>
	</Style>
    
	<Style x:Key="ButtonFocusVisual">
		<Setter Property="Control.Template">
			<Setter.Value>
				<ControlTemplate>
					<Rectangle Stroke="Black" StrokeDashArray="1 2" StrokeThickness="1" Margin="3" SnapsToDevicePixels="true"/>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>
	<LinearGradientBrush x:Key="ButtonNormalBackgroundFill" EndPoint="0.5,1" StartPoint="0.5,0">
		<GradientStop Color="#FFFFFFFF" Offset="0"/>
		<GradientStop Color="#FFF0F0EA" Offset="0.9"/>
	</LinearGradientBrush>
	<SolidColorBrush x:Key="ButtonBorder" Color="#FF003C74"/>
	<Style x:Key="CloseButtonStyle" TargetType="{x:Type Button}">
		<Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/>
		<Setter Property="Background" Value="{StaticResource ButtonNormalBackgroundFill}"/>
		<Setter Property="BorderBrush" Value="{StaticResource ButtonBorder}"/>
		<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
		<Setter Property="HorizontalContentAlignment" Value="Center"/>
		<Setter Property="VerticalContentAlignment" Value="Center"/>
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type Button}">
					<Microsoft_Windows_Themes:ButtonChrome x:Name="Chrome" SnapsToDevicePixels="true" RenderDefaulted="{TemplateBinding IsDefaulted}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}" ThemeColor="NormalColor" BorderBrush="{DynamicResource ButtonBorder}">
						<Microsoft_Windows_Themes:ButtonChrome.Fill>
							<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
								<GradientStop Color="#FFFF4747" Offset="0.234"/>
								<GradientStop Color="#FFFFA5A5" Offset="1"/>
							</LinearGradientBrush>
						</Microsoft_Windows_Themes:ButtonChrome.Fill>
						<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" RecognizesAccessKey="True"/>
					</Microsoft_Windows_Themes:ButtonChrome>
					<ControlTemplate.Triggers>
						<Trigger Property="IsKeyboardFocused" Value="true">
							<Setter Property="RenderDefaulted" TargetName="Chrome" Value="true"/>
						</Trigger>
						<Trigger Property="ToggleButton.IsChecked" Value="true">
							<Setter Property="RenderPressed" TargetName="Chrome" Value="true"/>
						</Trigger>
						<Trigger Property="IsEnabled" Value="false">
							<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
						</Trigger>
					</ControlTemplate.Triggers>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>
    
</ResourceDictionary>

标签: wpf

实例下载地址

WPF 自定义window 风格 示例源码下载

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警