WPF,如何自定义窗口

的风格V 2013-09-05 04:29:50
1:将WindowStyle设为None,可以隐藏标题栏,但最大化、最小化、还原图标是不是自己画呢?
2:我看网上有些资料是用WindowChrome创建自定义窗体,WindowChrome是什么东西啊?
3:各位大师,还有没有更好的自定义窗口的资料啊

谢谢
...全文
216 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
E次奥 2013-09-06
  • 打赏
  • 举报
回复
你自己画个就行了,可以不用WindowChrome!
  • 打赏
  • 举报
回复
引用 楼主 u011987817 的回复:
1:将WindowStyle设为None,可以隐藏标题栏,但最大化、最小化、还原图标是不是自己画呢? 2:我看网上有些资料是用WindowChrome创建自定义窗体,WindowChrome是什么东西啊? 3:各位大师,还有没有更好的自定义窗口的资料啊 谢谢
如果你的思想太八股了跟不上最近5年的时代,什么资料都会被你忽略的。
  • 打赏
  • 举报
回复
使用wpf开发透明窗口非常简单,只需要10秒钟。建议你花点时间研究一下。
  • 打赏
  • 举报
回复
你可以创建一个透明的window(那么当然就没有任何边框),然后在里边自己画所有的边框。例如这样一个软件窗口设计 它显然就必须是透明的window。 你可以搜一下如何做透明的wpf窗体,然后窗体里边的实际对象的界面随便你怎么设计,你想弄个傻傻的传统的有着什么“最大化、最小化”按钮的window也可以。
的风格V 2013-09-06
  • 打赏
  • 举报
回复
WindowChrome的用法,网上的资料好少哦!哪位大侠用过的?特别是修改右上角按钮的
程序人生high 2013-09-06
  • 打赏
  • 举报
回复
当前窗口状态改为:最大化

 this.WindowState = WindowState.Maximized;

加个按钮. 可以不用WindowChrome
的风格V 2013-09-06
  • 打赏
  • 举报
回复
引用 10 楼 porenasckx 的回复:
你自己画个就行了,可以不用WindowChrome!
用WindowChrome好些呢,还是不用?用WindowChrome好像不能自画关闭按钮形状哦
的风格V 2013-09-06
  • 打赏
  • 举报
回复
添加WindowChrome类的命名空间,在VS 2012中怎么找不到 System.Windows.Shell呢?
c2606050113 2013-09-05
  • 打赏
  • 举报
回复
引用 6 楼 c2606050113 的回复:
http://download.csdn.net/detail/c2606050113/6217279 需要的可以去看看,共同学习
c2606050113 2013-09-05
  • 打赏
  • 举报
回复
灬浪子灬 2013-09-05
  • 打赏
  • 举报
回复
<UserControl x:Class="ADS3_WPF_ControlLibrary.Master.UCTitleHead" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="40" > <Grid Name="grdTitleBar" VerticalAlignment="Top" Height="40" ><!--MouseMove="grdTitleBar_MouseMove"--> <Grid.Background> <ImageBrush Stretch="Fill" ImageSource="/ADS3_WPF;component/Images/Index/TOP-BK.png"/> </Grid.Background> <Grid.RowDefinitions> <RowDefinition/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="2" /> <ColumnDefinition Width="300" /> <ColumnDefinition Width="60*" /> <ColumnDefinition Width="30" /> <ColumnDefinition Width="10" /> </Grid.ColumnDefinitions> <Image Name="imgTitle" Grid.Column="1" Grid.Row="0" Source="/ADS3_WPF;component/Images/Index/TOP-mc.png" HorizontalAlignment="Left"></Image> <!--<Button Name="btnMinimize" Grid.Column="5" Grid.Row="0" Height="24" Width="24" Tag="/ADS3_WPF;component/Images/Index/i-zxh-2.png" Template="{StaticResource HoverImageButtonTemplate}" Click="btnMinimize_Click"> <Button.Background> <ImageBrush ImageSource="/ADS3_WPF;component/Images/Index/i-zxh-1.png" /> </Button.Background> </Button>--> <Button Name="btnClose" Grid.Column="3" Grid.Row="0" Height="24" Width="24" Tag="/ADS3_WPF;component/Images/Index/i-gb-2.png" Template="{StaticResource HoverImageButtonTemplate}" Click="btnClose_Click"> <Button.Background> <ImageBrush ImageSource="/ADS3_WPF;component/Images/Index/i-gb-1.png" /> </Button.Background> </Button> </Grid> </UserControl> using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using ADS3_WPF_ControlLibrary.PromptingFrame; namespace ADS3_WPF_ControlLibrary.Master { /// <summary> /// UCTitleHead.xaml 的交互逻辑 /// </summary> public partial class UCTitleHead : UserControl { public bool isCancel = false; private string messageText = string.Empty;//提示信息 public UCTitleHead() { InitializeComponent(); } ///// <summary> ///// 窗体的拖拽 ///// </summary> ///// <param name="sender"></param> ///// <param name="e"></param> //private void grdTitleBar_MouseMove(object sender, MouseEventArgs e) //{ // if (e.LeftButton == MouseButtonState.Pressed) // { // Window thisWindow = GetParentObject<Window>(this.grdTitleBar, "winParent"); // thisWindow.DragMove(); // } //} /// <summary> /// 获得父窗体控件 /// </summary> /// <typeparam name="T">要获得控件类名</typeparam> /// <param name="obj">当前子控件名</param> /// <param name="name">要查询父控件名</param> /// <returns>要获得控件类名</returns> public static T GetParentObject<T>(DependencyObject obj, string name) where T : FrameworkElement { DependencyObject parent = VisualTreeHelper.GetParent(obj); while (parent != null) { if (parent is T && (((T)parent).Name == name || string.IsNullOrEmpty(name))) { return (T)parent; } parent = VisualTreeHelper.GetParent(parent); } return null; } /// <summary> /// 设置提示的内容 /// </summary> /// <param name="messageContent"></param> public void setPromptMessageContent(string messageContent) { messageText = messageContent; } /// <summary> /// 关闭按钮事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnClose_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(messageText) == true) { isCancel = true; Window thisWindow = GetParentObject<Window>(this.grdTitleBar, "winParent"); thisWindow.Close(); return; } else { SelectFrame myFrame = new SelectFrame(messageText); myFrame.ShowDialog(); if (myFrame.isOk == true) { isCancel = true; Window thisWindow = GetParentObject<Window>(this.grdTitleBar, "winParent"); thisWindow.Close(); } } } } }
灬浪子灬 2013-09-05
  • 打赏
  • 举报
回复
头部可以自己做一个用户控件 比较通用
lhx527099095 2013-09-05
  • 打赏
  • 举报
回复
wpf里面就把window的样式换下就可以了啊 <Style TargetType="Window" x:Key="MessageboxWin"> <Setter Property="OverridesDefaultStyle" Value="true" /> <Setter Property="AllowsTransparency" Value="true" /> <Setter Property="SnapsToDevicePixels" Value="true" /> <Setter Property="ResizeMode" Value="NoResize" /> <Setter Property="WindowStyle" Value="None" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Window}"> <Grid Margin="10" OpacityMask="#F0000000"> <Rectangle Fill="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" RadiusX="5" RadiusY="5"> <Rectangle.Effect> <DropShadowEffect BlurRadius="10" ShadowDepth="0"/> </Rectangle.Effect> </Rectangle> <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Margin}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" CornerRadius="5"> <ContentPresenter /> </Border> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> <!--messagebox title bar --> <Style x:Key="MbxTitleBarBG" TargetType="Border"> <Setter Property="CornerRadius" Value="5 5 0 0" /> <Setter Property="Background"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FF6F6F6F" Offset="0" /> <GradientStop Color="#FFD1D1D1" Offset="1" /> </LinearGradientBrush> </Setter.Value> </Setter> </Style> <!--messagebox title close X --> <Style TargetType="Button" x:Key="MbxTitleBarClose"> <Setter Property="HorizontalAlignment" Value="Right"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <TextBlock Text="X" Margin="15 0" Foreground="{TemplateBinding Foreground}" FontWeight="Bold" HorizontalAlignment="Right" VerticalAlignment="Center" Cursor="Hand" > </TextBlock> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Foreground" Value="#FFFF393C"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style TargetType="Button" x:Key="MbxSureBtn"> <Setter Property="Width" Value="70"/> <Setter Property="Height" Value="25"/> <Setter Property="Cursor" Value="Hand"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border CornerRadius="2" x:Name="BG"> <Border.Background> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FFBABABA" Offset="1" /> <GradientStop Color="#FFE8E8E8" Offset="0" /> </LinearGradientBrush> </Border.Background> <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" /> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Background" TargetName="BG" > <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FF969696" Offset="1" /> <GradientStop Color="#FFD1D1D1" Offset="0" /> </LinearGradientBrush> </Setter.Value> </Setter> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> 以前写的messagebox的window
threenewbee 2013-09-05
  • 打赏
  • 举报
回复
http://msdn.microsoft.com/zh-cn/library/system.windows.shell.windowchrome.aspx
threenewbee 2013-09-05
  • 打赏
  • 举报
回复
但最大化、最小化、还原图标是不是自己画呢 是的,如果你不用系统默认的,就只能自己画。

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧