简体   繁体   English

WPF自定义Chrome窗口?

[英]WPF Custom Chrome Window?

i have been trying to make something along the lines of this... 我一直试图做出类似的事情... 在此输入图像描述

I have looked and looked and only found this article . 我看了看,只发现了这篇文章 I am having trouble integrating this into my application. 我无法将其集成到我的应用程序中。 I just started WPF today, so i am learning. 我今天刚刚开始WPF,所以我正在学习。 I have downloded the window.Shell dLL. 我已经下载了窗口。壳牌dLL。 What else do i need? 我还需要什么? Thanks! 谢谢!

If you are looking for a step-by-step guide on how to add this to your application I can give it a try; 如果您正在寻找有关如何将其添加到您的应用程序的分步指南,我可以尝试一下; I just happened to need a bit of a brush-up for a small app, I liked this and gave it a try - it took me about 45 minutes to apply. 我碰巧需要为一个小应用程序进行一些刷新,我喜欢这个并尝试一下 - 我花了大约45分钟申请。 Cool stuff actually! 很酷的东西!

First: Download the source application and extract it to your computer. 第一步:下载应用程序并将其解压缩到您的计算机。

In it you will find three subfolders. 在其中,您将找到三个子文件夹。 One with the sample application, one named Microsoft.Windows.Shell, one named CustomChromeLibrary. 一个是示例应用程序,一个名为Microsoft.Windows.Shell,一个名为CustomChromeLibrary。 Copy the latter two to the root folder of your project map, add them to your project map (add existing project) and, from your startup project, reference them. 后两个复制到项目地图的根文件夹,将其添加到您的项目地图(添加现有项目),并从你的启动项目, 引用它们。

Now open the Window you want to apply CustomChromeLibrary to. 现在打开要应用CustomChromeLibrary的窗口。 You need to change the root from 您需要更改根目录

<Window> 

to

<ccl:CustomChromeWindow>

, this is done by using this code as the document root: ,这是通过使用此代码作为文档根目录来完成的:

<ccl:CustomChromeWindow 
Title="YourWindowTitle" Height="268" Width="733" ResizeMode="CanResize" 
x:Class="YourNamespace.YourWindow"
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"
xmlns:ccl="clr-namespace:CustomChromeLibrary;assembly=CustomChromeLibrary"
xmlns:local="clr-namespace:YourNamespace" 
>

Pay attention to the last three lines in the sample. 注意样本中的最后三行。 These need to be updated to reference the correct libraries; 这些需要更新以引用正确的库; the last one actually referencing to YOUR namespace. 最后一个实际引用您的命名空间。

Next you need to update the source code of your window as this is still a simple Window and you will receive an error from it. 接下来,您需要更新窗口的源代码,因为这仍然是一个简单的窗口,您将收到错误。

Change this 改变这个

public partial class YourWindow : Window

to this 对此

public partial class YourWindow : CustomChromeLibrary.CustomChromeWindow

You are already half way there! 你已经到了一半了!

Next you just need to create the objects for your window (title bar etc.). 接下来,您只需要为窗口创建对象(标题栏等)。 This is wonderfully done in the sample project No. 5 ; 这在5号样本项目中完成得非常出色; I did really just copy it. 我真的只是复制它。

Take everything from 从中获取一切

<shell:WindowChrome.WindowChrome>
    <shell:WindowChrome
    ...

to here 到这里

    <!--min/max/close buttons-->
    <ccl:CaptionButtons/>

Now you can fill your Window like this 现在你可以像这样填充你的窗口

    <Grid> 
        The content of your Window goes here 
    </Grid>

And close the xaml like this 并像这样关闭xaml

    </Grid>
</ccl:CustomChromeWindow>

Now, if you try to run this you will receive another error. 现在,如果您尝试运行此操作,您将收到另一个错误。 There are still three files missing: 仍然缺少三个文件:

The first one you need is a Microsoft file: CaptionButtonRectToMarginConverter.cs; 您需要的第一个是Microsoft文件:CaptionButtonRectToMarginConverter.cs; you will also find it in the sample. 你也会在样本中找到它。 Copy it to your project and add it (add existing file). 将其复制到您的项目并添加它(添加现有文件)。

You need to make one change to it: 您需要对其进行一处更改:

namespace YourNamespace
{ ...

instead of the sample's namespace. 而不是样本的命名空间。

Finally you need the two xaml files that create the buttons: GlassButton.xaml and GlassIcon.xaml; 最后,您需要两个创建按钮的xaml文件:GlassButton.xaml和GlassIcon.xaml; they can be found in the "Resources" subfolder (and are referenced as resource dictionaries in the xaml). 它们可以在“Resources”子文件夹中找到(并在xaml中作为资源字典引用)。 Copy the whole subfolder to your project and add the two files to your project (add existing file). 将整个子文件夹复制到项目中,并将两个文件添加到项目中(添加现有文件)。

Now you should finally be able to run your project. 现在你应该最终能够运行你的项目了。

Let's not forget this: Lots of kudos to gbahns , the author of the original article over at codeplex.com! 让我们不要忘记这一点: gbahns的很多荣誉,是codeplex.com上原始文章的作者!

There are quite a few implementations you can find for a custom chrome. 您可以找到很多自定义chrome的实现。

Another helper library I've seen to one you linked is 我见过的另一个帮助库是你链接的

MahApps.Metro MahApps.Metro

Read section 3. It can be setup with Nuget making it more easier to integrate for someone new. 阅读第3节。可以使用Nuget进行设置,使其更容易为新用户集成。

Also section 3.3 3.4 3.5 talk about customising and expanding the MetroWindow control which gives you a custom chrome and also allows adding controls to the chrome title bar 3.3节3.5 3.5讨论自定义和扩展MetroWindow控件,它为您提供自定义chrome,还允许向chrome标题栏添加控件

Over in this stack overflow question: 在这个堆栈溢出问题:

How can I add a button to the WPF caption bar while using custom window chrome? 如何在使用自定义窗口镶边时向WPF标题栏添加按钮?

I was asking about how to insert buttons into the title bar of my Custom Window Chrome window. 我问的是如何在我的自定义窗口Chrome窗口的标题栏中插入按钮。 The xaml example might be enough to help you get going. xaml示例可能足以帮助您开始。

Other than that, I'm not sure what you are looking for. 除此之外,我不确定你在寻找什么。

Edit: The button style I have in that other post is a fairly simplistic button, but you should be able to replace it with any styling that you want. 编辑:我在其他帖子中的按钮样式是一个相当简单的按钮,但您应该能够用您想要的任何样式替换它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM