如何制作自定义WPF窗口样式? [英] How to make a Custom WPF window Style?

查看:169
本文介绍了如何制作自定义WPF窗口样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮我制作一个自定义WPF窗口样式,所有窗口效果(我认为它称为DWM效果)没有Aero边框(包括Form Shadow,Dock by cursor,系统调整大小不使用mouse_down和mouse_move事件,开始/关闭动画由Windows Aero Effects完成,光标无法在持有表单时移动任务栏(移动)等等)我已经在win form app中完成了它与Office 2013完全相同的主题所有效果我提到过。

解决方案

我在回答的过程中大部分回答,请参阅:如何加速我的vb.net应用程序? [ ^ ]。



我只想添加关于Windows效果和Aero的内容。这些效果不属于您的系统,而是属于操作系统,这是定义使用哪些效果的用户。你的应用程序无法摆脱它们中的大部分。



但是,如果你愿意,你可以摆脱Aero。更准确地说,您可以拒绝在Windows游戏中玩窗口边框内的所有内容。或多或少清楚如何在Windows的客户区域中执行此操作,但如何处理非客户区域,包括标题栏和边框。创建自己的风格,完全独立于Windows设置可能是有道理的。



这是我的处方:完全摆脱非客户区域!方法如下:将其属性 WindowStyle 设置为 System.Windows.WindowStyle.None

http://msdn.microsoft.com/en-us/library/system .windows.window.windowstyle.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.windows.windowstyle.aspx [ ^ ]。



它将删除非客户区域完全。但是你应该明白,你将松开应用程序图标及其菜单,标题栏和拖动窗口的能力,所有按钮:没有最小化/最大化/恢复等。你需要通过自己的控件来模拟它。但这一次,完全定制。好吧,来想想,你问了。 :-)



是的,我读到了DWM效果,但它就是这样......



祝你好运,

-SA


要真正控制WPF中的窗口样式,你需要将样式设置为''没有''然后画你自己的。一旦你完成了,你就可以画任何你喜欢的东西。


嘿,我找到了解决方案:



首先:下载WPF Shell集成库此处 [ ^ ]

然后使用此XML代码:



 <  窗口    x:Class   =  MyLibrary。 MainWindow  

xmlns = http://schemas.microsoft.com/winfx/2006/xaml/presentation

xmlns:x = http://schemas.microsoft.com/winfx/2006/xaml

xmlns:shell = http://schemas.microsoft.com/winfx/2006/xaml/presentation/shell

标题 = MainWindow

WindowStyle = SingleBorderWindow

< span class =code-attribute> ResizeMode = CanResizeWithGrip

mc:可忽略 = d

xmlns:d = http://schemas.microsoft.com/expression/blend/2008

xmlns:mc = http://schemas.openxmlformats.org/markup-compatibility/2006

d:DesignHeight = 449

d:DesignWidth = 677

< span class =code-attribute> 前景 = 白色

已移除 = 黑色 >

< shell:WindowChrome.WindowChrome >
< shell:WindowChrome < span class =code-attribute> CaptionHeight = 35

< span class =code-attribute> GlassFrameThickness = 0,0,0,1

< span class =code-attribute> ResizeBorderThickness = 5 / >
< / shell:WindowChrome.WindowChrome >

< 网格 x:名称 = LayoutRoot > ;

< / Grid >
< / Window >





(注意,您需要引用 Microsoft.Windows.Shell


Hi, can someone help me to make a Custom WPF window style with all windows effects(I think it is called DWM effects) without the Aero border (and includes Form Shadow, Dock by cursor, system resize not using mouse_down and mouse_move events, starting/closing animation that is done by windows Aero Effects, the cursor cannot cross the Taskbar when holding the form(moving) and so on) I already done it in win form app absolutely the same theme of Office 2013 with all effects that I mentioned.

解决方案

I mostly answered in my previous answer, please see: How to speed up my vb.net application?[^].

I only want to add about Windows effects and Aero. These effects does not belong to your system, but to the OS and this is the user who defines which ones are used. Your application cannot get rid of most of them.

However, if you want, you can get rid of Aero. More exactly, you can deny playing in Windows games with everything which lies inside your window border. It is more or less clear how to do it in your client area of your windows, but how to do with the non-client area, which includes title bar and the borders. It may makes sense, to create your own style, fully independent on Windows settings.

Here is my prescription for that: get rid of non-client areas at all! Here is how: set its property WindowStyle to System.Windows.WindowStyle.None:
http://msdn.microsoft.com/en-us/library/system.windows.window.windowstyle.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.windowstyle.aspx[^].

It will remove non-client areas completely. But you should understand that you will loose the application icon and its menu, title bar and the ability to drag a window, all buttons: no minimize/maximize/restore, etc. You will need to simulate it all by you own controls. But this time, fully custom. Well, come to think about, you asked for it. :-)

Yes, I read about DWM effect, but it is what it is…

Good luck,
—SA


To really take control of window styles in WPF, you need to set the style to ''none'' and then draw your own. Once you''ve done that, you can draw anything you like.


Hey I''ve found the solution :

first : Download the WPF Shell Integration Library Here[^]
then use this XML Code :

<Window x:Class="MyLibrary.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        xmlns:shell="http://schemas.microsoft.com/winfx/2006/xaml/presentation/shell"

        Title="MainWindow"

        WindowStyle="SingleBorderWindow"

        ResizeMode="CanResizeWithGrip"

        mc:Ignorable="d"

        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

        d:DesignHeight="449"

        d:DesignWidth="677"

        Foreground="White"

        removed="Black">

    <shell:WindowChrome.WindowChrome>
        <shell:WindowChrome CaptionHeight="35"

                            GlassFrameThickness="0,0,0,1"

                            ResizeBorderThickness="5" />
    </shell:WindowChrome.WindowChrome>

    <Grid x:Name="LayoutRoot">

    </Grid>
</Window>



(note, you need to have referenced Microsoft.Windows.Shell)


这篇关于如何制作自定义WPF窗口样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆