【发布时间】:2014-03-19 17:32:26
【问题描述】:
当 ResizeMode=CanResize 时,我想要的是能够在 WPF 中为应用程序镶边的可调整大小边框着色(样式) - 看来这是不可能的。所以我想设置 ResizeMode=NoResize 然后自己处理调整大小。
我将如何实现我的应用程序 chrome 的自定义调整大小实现?
这可能吗,事实上我知道这是可能的,因为 VS.Net 具有调整大小的能力,但它周围没有标准的“灰色”边框?
【问题讨论】:
当 ResizeMode=CanResize 时,我想要的是能够在 WPF 中为应用程序镶边的可调整大小边框着色(样式) - 看来这是不可能的。所以我想设置 ResizeMode=NoResize 然后自己处理调整大小。
我将如何实现我的应用程序 chrome 的自定义调整大小实现?
这可能吗,事实上我知道这是可能的,因为 VS.Net 具有调整大小的能力,但它周围没有标准的“灰色”边框?
【问题讨论】:
我为类似的问题争论不休,最终采用了 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 风格窗口镶边的库。 您可能想调查它们并考虑它们是否是您正在寻找的东西。
这里有几个:
还可以通过使用低于 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?
祝你好运。
【讨论】: