WPF无边界应用程序,如何调整大小? [英] WPF Borderless Application, How to make resizable?!

查看:108
本文介绍了WPF无边界应用程序,如何调整大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过使主窗口不可见来创建了无边界应用程序,然后创建了边界并调整了拐角半径以使我的应用程序看起来更吸引人.

我做了最小化/最大化/关闭按钮,尽管当应用程序最大化时,边框保持相同的高度和宽度.我希望它可以使高度和宽度在最大化时发生变化,或者具有被拖动到更宽的能力等.

我知道可以将主窗口的大小调整为"CanResize"或"CanResizeWithGrip",但是这些功能并非仅适用于边框.

有人知道我能解决这个问题吗?即使边框可调整大小?!

任何帮助表示赞赏.谢谢.

这是我的XAML:

I have created a borderless application by making the main window invisible, then I created a border and adjusted the corner radius to make my application look appealing.

I have made the minimize/maximize/close buttons although when the application is maximized the border stays the same height and width. I would like it so the height and width would change when maximized or have the ability to be dragged wider etc.

I know the main window can be made resizeable either "CanResize" or "CanResizeWithGrip" however these functions are not available solely to the border.

Does anyone know how I am able to solve this? i.e. Make the border resizable?!

Any help is appreciated. Thanks.

Here is my XAML:

Title="TITLE" Height="400" Width="600" AllowsTransparency="True" WindowStyle="None" Background="{x:Null}" Icon="/TITLE;component/Images/TITLE1.png">
    <Grid>
        <Border BorderBrush="#50000000" BorderThickness="4" HorizontalAlignment="Left" Margin="12,12,0,0" Name="TITLEBorder" VerticalAlignment="Top" CornerRadius="100,40,100,40" MouseLeftButtonDown="TITLEBorder_MouseLeftButtonDown" MinWidth="554" MinHeight="337" MaxWidth="Infinity" MaxHeight="Infinity" >
            <Border.Effect>
                <DropShadowEffect x:Name="TITLEBorderShdw" BlurRadius="44" ShadowDepth="0" Color="Black"></DropShadowEffect>
            </Border.Effect>
            <Border.Background>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#8649E3BA" Offset="0" />
                    <GradientStop Color="#89FFFFFF" Offset="1" />
                    <GradientStop Color="#AF4CA2CC" Offset="0.639" />
                </LinearGradientBrush>
            </Border.Background>
            <Grid>
                <Button Name="CloseButton" Style="{StaticResource ResourceKey=CloseButton}" Height="20" Width="20" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="20,4" Click="CloseButton_Click" />
                <Button Name="MinimizeButton" Height="20" Width="20" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="64,4" Style="{StaticResource ResourceKey=MinimizeButton}" Click="MinimizeButton_Click" />
                <Button Name="MaximizeButton" Style="{StaticResource ResourceKey=MaximizeButton}" Height="20" Width="20" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="42,4" 

Click="MaximizeButton_Click" />
                <Button Name="RestoreButton" Style="{StaticResource ResourceKey=RestoreButton}" Height="20" VerticalAlignment="Top" Margin="484,4,42,0" Click="RestoreButton_Click" />
            </Grid>
        </Border>
    </Grid>
</Window>



好吧,我已经做了这些改进;我现在想要调整大小?通过抓握或使用google找到的这一段,尽管没有说明您将需要在小部件上跟踪mouseEvents,如果鼠标在特定的角落,请更改光标.
然后捕获鼠标按下事件,并根据鼠标移动事件调整窗口小部件的大小. ",帮助/说明?



Okay, I have made these improvements; I would now like it to be resizable? either by grip or this paragraph which was found using google, although it was not explained "You wil need to trace mouseEvents on your widget, change the cursor if the mouse in a specific corner.
Then catch mouse press events and resize your widget on mouse move events. ", Help/Explaination?

Title="TITLE" AllowsTransparency="True" WindowStyle="None" Background="{x:Null}" Icon="/TITLE;component/Images/TITLE1.png">
 <Grid>
     <Border BorderBrush="#50000000" BorderThickness="4" HorizontalAlignment="Right" Margin="12,12,0,0" Name="TITLEBorder" VerticalAlignment="Stretch" CornerRadius="100,40,100,40" MouseLeftButtonDown="TITLEBorder_MouseLeftButtonDown" Width="640" Height="360" >

推荐答案

您已经将VerticalAlignmentHorizontalAlignment设置为TopLeft,所以您要告诉WPF您想要在左上角的Border并根据Border的子级的所需大小来调整边框的大小.
因此,删除VerticalAlignmentHorizontalAlignment或将它们设置为Stretch.


ResizeMode设置为CanResize,然后可以调整窗口大小.现在,据我所知,出于某种原因,您想调整Border而不是窗口的大小.唯一的方法就是自己实现功能.

0)您需要用户可以随意调整大小的内容,例如Thumb或任何Control会做的事情.我建议您使用缩略图 [
You''ve set VerticalAlignment and HorizontalAlignment to Top and Left so you''re telling WPF that you want the Border in the upper left corner and to size the border based on the desired size of the Child of the Border.
So Remove VerticalAlignment and HorizontalAlignment or set them to Stretch.


Set ResizeMode to CanResize then you can resize your window. Now as I understand you want to resize the Border and not the window, for some reason. The only way to do that is to implement the functionality yourself.

0) You''ll need something the user can crap onto to resize, like a Thumb or any Control would do. I suggest you use Thumb[^]
1) You must handle the appropriate events; MouseXX/DragXX depending on what you chose in 1)
2) You must update the width and height of the Border yourself in the appropriate event.


这篇关于WPF无边界应用程序,如何调整大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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