WPF + AeroGlass +功能区问题[VS 2010,VB] [英] WPF + AeroGlass + Ribbon problem [VS 2010, VB]
问题描述
在我的WPF应用程序中,我使用Ribbon。我使用RibbonWindow而不是Window来使QAT出现在标题栏上。我也想申请"玻璃"效果到Ribbon下面的区域。但是,GlassWindow不能使用玻璃效果 - 它仅适用于Window。有没有解决这个问题的方法?
这里是代码:
AeroGlass代码:
Imports System.Windows.Interop
Imports System.Collections.Generic
Imports System.Runtime.InteropServices
Public Class AeroGlass
< StructLayout(LayoutKind .Sequential)GT;
Public Structure Margins
Public cxLeftWidth As Integer
Public cxRightWidth As Integer
Public cyTopHeight As Integer
Public cyBottomHeight As Integer
End Structure
公共共享函数GetDpiAdjustedMargins(ByVal windowHandle As IntPtr,ByVal left As Integer,ByVal right As Integer,ByVal top As Integer,ByVal bottom As Integer)As Margins
'系统DPI。
Dim desktop As System.Drawing.Graphics = System.Drawing.Graphics.FromHwnd(windowHandle)
Dim DesktopDpiX As Single = desktop.DpiX
Dim DesktopDpiY As Single = desktop.DpiY
'保证金。
Dim margin如新AeroGlass.Margins()
marginins.cxLeftWidth = Convert.ToInt32(left *(DesktopDpiX / 96))
marginins.cxRightWidth = Convert.ToInt32(right *(DesktopDpiX / 96))
marginins.cyTopHeight = Convert.ToInt32(top *(DesktopDpiX / 96))
marginins.cyBottomHeight = Convert.ToInt32(right *(DesktopDpiX / 96))
返回保证金
结束函数
< DllImport(" DwmApi.dll")>
公共共享函数DwmExtendFrameIntoClientArea(ByVal hwnd As IntPtr,ByRef pMarInset As Margins)As Integer
End Function
Public Shared Sub ExtendGlass(ByVal win As Window,ByVal left As Integer, ByVal right As Integer,ByVal top As Integer,ByVal bottom As Integer)
'获取应用程序的窗口句柄。
Dim windowInterop As New WindowInteropHelper(win)
Dim windowHandle As IntPtr = windowInterop.Handle
Dim mainWindowSrc As HwndSource = HwndSource.FromHwnd(windowHandle)
mainWindowSrc.CompositionTarget.BackgroundColor = Colors .Transparent
Dim margin如AeroGlass.Margins = AeroGlass.GetDpiAdjustedMargins(windowHandle,left,right,top,bottom)
Dim returnVal As Integer = AeroGlass.DwmExtendFrameIntoClientArea(mainWindowSrc.Handle,margin)
如果returnVal< 0然后
抛出新的NotSupportedException("操作失败。")
结束如果
结束次级
结束类
这是MainWindow.xaml
< r:RibbonWindow x:Class =" ;主窗口"
xmlns =" http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x =" http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:r =" clr-namespace:Microsoft.Windows.Controls.Ribbon; assembly = RibbonControlsLibrary"
Title =" Bonus"高度= QUOT; 500"宽度= QUOT; 580" WindowStartupLocation = QUOT;中心屏幕"
Loaded =" Window_Loaded"闭= QUOT; MainWindow_Closing"背景= QUOT;透明">
< Grid>
< Grid.RowDefinitions>
< RowDefinition Height =" Auto" />
< RowDefinition />
< /Grid.RowDefinitions>
<! - RIBBON - >
< r:Ribbon x:Name =" rx" Title =" {Binding RelativeSource = {RelativeSource FindAncestor,AncestorType = {x:Type Window}},Path = Title}">
<! - LALALALA - >
< / r:Ribbon>
<! - END RIBBON - >
< / r:RibbonWindow>
这是MainWindow.xaml.vb
Imports Ribbon = Microsoft.Windows.Controls.Ribbon
Class MainWindow
Private Sub Window_Loaded(ByVal sender As System .Object,ByVal e As System.Windows.RoutedEventArgs)
Me.Resources.MergedDictionaries.Add(Ribbon.PopularApplicationSkins.Office2007Silver)
如果Environment.OSVersion.Version.Major> = 6那么
AeroGlass.ExtendGlass(Me,-1,-1,-1,-1)
End if
End Sub
End Class
没有不知道的知识。
检查出来
http://blogs.msdn.com/llobo/archive/2010/05/10/wpf-shell-integration-library.aspx
In my WPF application I use Ribbon. I used RibbonWindow instead of Window to make QAT appear on title bar. Also I wanna apply "glass" effect to area below Ribbon. However, glass effect doesn't work with RibbonWindow - it works only with Window. Is there any solution to this problem?
Here's code:
AeroGlass code:
Imports System.Windows.Interop
Imports System.Collections.Generic
Imports System.Runtime.InteropServices
Public Class AeroGlass
<StructLayout(LayoutKind.Sequential)>
Public Structure Margins
Public cxLeftWidth As Integer
Public cxRightWidth As Integer
Public cyTopHeight As Integer
Public cyBottomHeight As Integer
End Structure
Public Shared Function GetDpiAdjustedMargins(ByVal windowHandle As IntPtr, ByVal left As Integer, ByVal right As Integer, ByVal top As Integer, ByVal bottom As Integer) As Margins
' System DPI.
Dim desktop As System.Drawing.Graphics = System.Drawing.Graphics.FromHwnd(windowHandle)
Dim DesktopDpiX As Single = desktop.DpiX
Dim DesktopDpiY As Single = desktop.DpiY
' Margins.
Dim margins As New AeroGlass.Margins()
margins.cxLeftWidth = Convert.ToInt32(left * (DesktopDpiX / 96))
margins.cxRightWidth = Convert.ToInt32(right * (DesktopDpiX / 96))
margins.cyTopHeight = Convert.ToInt32(top * (DesktopDpiX / 96))
margins.cyBottomHeight = Convert.ToInt32(right * (DesktopDpiX / 96))
Return margins
End Function
<DllImport("DwmApi.dll")>
Public Shared Function DwmExtendFrameIntoClientArea(ByVal hwnd As IntPtr, ByRef pMarInset As Margins) As Integer
End Function
Public Shared Sub ExtendGlass(ByVal win As Window, ByVal left As Integer, ByVal right As Integer, ByVal top As Integer, ByVal bottom As Integer)
' Get window handle for app.
Dim windowInterop As New WindowInteropHelper(win)
Dim windowHandle As IntPtr = windowInterop.Handle
Dim mainWindowSrc As HwndSource = HwndSource.FromHwnd(windowHandle)
mainWindowSrc.CompositionTarget.BackgroundColor = Colors.Transparent
Dim margins As AeroGlass.Margins = AeroGlass.GetDpiAdjustedMargins(windowHandle, left, right, top, bottom)
Dim returnVal As Integer = AeroGlass.DwmExtendFrameIntoClientArea(mainWindowSrc.Handle, margins)
If returnVal < 0 Then
Throw New NotSupportedException("Operation failed.")
End If
End Sub
End Class
Here's MainWindow.xaml
<r:RibbonWindow x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:r="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
Title="Bonus" Height="500" Width="580" WindowStartupLocation="CenterScreen"
Loaded="Window_Loaded" Closing="MainWindow_Closing" Background="Transparent">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<!-- RIBBON -->
<r:Ribbon x:Name="rx" Title="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=Title}">
<!-- LALALALA-->
</r:Ribbon>
<!-- END RIBBON -->
</r:RibbonWindow>
Here's MainWindow.xaml.vb
Imports Ribbon = Microsoft.Windows.Controls.Ribbon
Class MainWindow
Private Sub Window_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
Me.Resources.MergedDictionaries.Add(Ribbon.PopularApplicationSkins.Office2007Silver)
If Environment.OSVersion.Version.Major >= 6 Then
AeroGlass.ExtendGlass(Me, -1, -1, -1, -1)
End If
End Sub
End Class
There is no knowledge that is not power.
check this out
http://blogs.msdn.com/llobo/archive/2010/05/10/wpf-shell-integration-library.aspx
这篇关于WPF + AeroGlass +功能区问题[VS 2010,VB]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!