ResizeMode = NoResize时如何使窗口可调整大小

时间:2014-03-19 17:32:27

标签: .net wpf xaml

我想要的是能够在ResizeMode = CanResize时对WPF中应用程序镶边的可调整大小边框进行着色(样式) - 看起来这是不可能的。所以我想设置ResizeMode = NoResize,然后自己处理调整大小。

我如何实现应用程序chrome的自定义调整大小实现?

这是否可能,事实上我知道这是可能的,因为VS.Net具有调整大小的能力但没有标准的灰色'它周围的边界?

1 个答案:

答案 0 :(得分:0)

我遇到了类似的问题,并最终采用了Haider M. al-Khateeb here使用的非常好的方法。

他没有提供开箱即用的XAML,所以这是我的。 在MainWindow.xaml中,在z顺序的顶部,放置:

<Grid x:Name="Scalers">
    <Rectangle x:Name="Top" Height="6" VerticalAlignment="Top" PreviewMouseDown="Resize" MouseMove="DisplayResizeCursor" Margin="8,0" Fill="Transparent" MouseLeave="ResetCursor" />
    <Rectangle x:Name="Bottom" Height="6" VerticalAlignment="Bottom" PreviewMouseDown="Resize" MouseMove="DisplayResizeCursor" Margin="8,0" Fill="Transparent" MouseLeave="ResetCursor" />
    <Rectangle x:Name="Left" Width="6" HorizontalAlignment="Left" PreviewMouseDown="Resize" MouseMove="DisplayResizeCursor" Margin="0,8" Fill="Transparent" MouseLeave="ResetCursor" />
    <Rectangle x:Name="Right" Width="6" HorizontalAlignment="Right" PreviewMouseDown="Resize" MouseMove="DisplayResizeCursor" Margin="0,8" Fill="Transparent" MouseLeave="ResetCursor" />
    <Rectangle x:Name="BottomLeft" Width="8" Height="8" HorizontalAlignment="Left" VerticalAlignment="Bottom" PreviewMouseDown="Resize" MouseMove="DisplayResizeCursor" Fill="Transparent" MouseLeave="ResetCursor" />
    <Rectangle x:Name="BottomRight" Width="8" Height="8" HorizontalAlignment="Right" VerticalAlignment="Bottom" PreviewMouseDown="Resize" MouseMove="DisplayResizeCursor" Fill="Transparent" MouseLeave="ResetCursor" />
    <Rectangle x:Name="TopLeft" Width="8" Height="8" HorizontalAlignment="Left" VerticalAlignment="Top" PreviewMouseDown="Resize" MouseMove="DisplayResizeCursor" Fill="Transparent" MouseLeave="ResetCursor" />
    <Rectangle x:Name="TopRight" Width="8" Height="8" HorizontalAlignment="Right" VerticalAlignment="Top" PreviewMouseDown="Resize" MouseMove="DisplayResizeCursor" Fill="Transparent" MouseLeave="ResetCursor" />
</Grid>

这种方法会产生一些问题。 您必须自己决定用多少空间来调整区域大小以及这将如何影响位于窗口边界的内容。此外,我注意到这有点不稳定,但它确实起到了作用。

最后,显而易见的问题是当 ResizeMode = NoResize CanMinimize 时,用户无法通过将窗口拖到窗口来最大化窗口顶部或通过在最大化时向下拖动将其恢复到正常大小,因此您可能希望编写一些代码来处理该情况。当用户双向拖动时,也不要忘记切换最大化/恢复。

在另一个方向,有许多库提供自定义Metro风格窗口chrome。 您可能希望调查它们并考虑它们是否是您正在寻找的。

以下是一些:

还可以通过播放WPF级别以下的内容来修改窗口镶边(例如,Office 2010)。这是一项非常重要的任务,但是可行。 请参见以下页面中的“在扩展框架窗口中绘图”:

https://msdn.microsoft.com/en-us/library/bb688195(VS.85).aspx

您可能希望仔细阅读以下链接,以获取有关更改窗口铬的主题的一些入门知识。

https://blogs.msdn.microsoft.com/wpfsdk/2008/09/08/custom-window-chrome-in-wpf/

https://blogs.msdn.microsoft.com/adam_nathan/2006/05/04/aero-glass-inside-a-wpf-window/


以下问题也可能与阅读有用: Changing the colour of Aero glass for my window?


祝你好运。