我正在處理WPF應用程序,我正在使用一個Telerik對話框控件,它顯示爲一個Window,但實際上並不是一個Window對象。由於它不是一個實際的窗口(但它的外觀和行爲像一個),它的風格與我的應用程序中使用的其餘對話框不匹配。檢索Windows「窗口顏色」
所以,我爲這個對話框創建了一個模板,並且正在將系統顏色分配給模板,以便對話框使用相同的顏色並且具有與普通窗口相同的外觀和風格。
出於某種原因,我無法找到「窗口顏色」的系統顏色(不是窗口背景顏色,這個很容易找到......我說的是實際的窗口顏色......框架和窗口的標題)
我已經通過了所有的System.Windows.SystemColors,但無法找到定義「窗口顏色」的系統顏色......就像我所說的,我不想引用「窗口的背景顏色」。
我想知道是否有人知道如何檢索這種顏色。
編輯: 這是我在嘗試確定哪種系統顏色用於窗口顏色時實現的一些代碼。
以下WPF代碼是一組邊框,其背景設置爲可用的每種系統顏色......具有系統顏色名稱的TextBlock位於每個邊框內。
如果你想看看自己,把下列一個窗口或東西,這樣你可以看到它:
<ScrollViewer>
<StackPanel>
<-- here I had another Stack Panel referencing the Brushes
instead of using the Keys. I wanted the application to be dynamic
so that if the user changed colors it would be reflected in
the application on the fly...-->
<StackPanel>
<StackPanel.Resources>
<Style TargetType="TextBlock">
<Setter Property="Foreground" Value="White" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="Effect">
<Setter.Value>
<DropShadowEffect BlurRadius="4" Color="Black" ShadowDepth="0"/>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="Border">
<Setter Property="BorderBrush" Value="Red"/>
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Margin" Value="2"/>
<Setter Property="Height" Value="20"/>
</Style>
</StackPanel.Resources>
<Border>
<Border.Background>
<SolidColorBrush Color="{DynamicResource {x:Static SystemColors.WindowColorKey}}"/>
</Border.Background>
<TextBlock Text="SystemColors.WindowColorKey" />
</Border>
<Border Background="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}" >
<TextBlock Text="SystemColors.ActiveBorderBrushKey" />
</Border>
<Border Background="{DynamicResource {x:Static SystemColors.ActiveCaptionBrushKey}}" >
<TextBlock Text="SystemColors.ActiveCaptionBrushKey" />
</Border>
<Border Background="{DynamicResource {x:Static SystemColors.ActiveCaptionTextBrushKey}}" >
<TextBlock Text="SystemColors.ActiveCaptionTextBrushKey" />
</Border>
<Border Background="{DynamicResource {x:Static SystemColors.AppWorkspaceBrushKey}}" >
<TextBlock Text="SystemColors.AppWorkspaceBrushKey" />
</Border>
<Border Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" >
<TextBlock Text="SystemColors.ControlBrushKey" />
</Border>
<Border Background="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}" >
<TextBlock Text="SystemColors.ControlDarkBrushKey" />
</Border>
<Border Background="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}" >
<TextBlock Text="SystemColors.ControlDarkDarkBrushKey" />
</Border>
<Border Background="{DynamicResource {x:Static SystemColors.ControlLightBrushKey}}" >
<TextBlock Text="SystemColors.ControlLightBrushKey" />
</Border>
<Border Background="{DynamicResource {x:Static SystemColors.ControlLightLightBrushKey}}" >
<TextBlock Text="SystemColors.ControlLightLightBrushKey" />
</Border>
<Border Background="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" >
<TextBlock Text="SystemColors.ControlTextBrushKey" />
</Border>
<Border Background="{DynamicResource {x:Static SystemColors.DesktopBrushKey}}" >
<TextBlock Text="SystemColors.DesktopBrushKey" />
</Border>
<Border Background="{DynamicResource {x:Static SystemColors.GradientActiveCaptionBrushKey}}" >
<TextBlock Text="SystemColors.GradientActiveCaptionBrushKey" />
</Border>
<Border Background="{DynamicResource {x:Static SystemColors.GradientInactiveCaptionBrushKey}}" >
<TextBlock Text="SystemColors.GradientInactiveCaptionBrushKey" />
</Border>
<Border Background="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" >
<TextBlock Text="SystemColors.GrayTextBrushKey" />
</Border>
<Border Background="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" >
<TextBlock Text="SystemColors.HighlightBrushKey" />
</Border>
<Border Background="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}" >
<TextBlock Text="SystemColors.HighlightTextBrushKey" />
</Border>
<Border Background="{DynamicResource {x:Static SystemColors.HotTrackBrushKey}}" >
<TextBlock Text="SystemColors.HotTrackBrushKey" />
</Border>
<Border Background="{DynamicResource {x:Static SystemColors.InactiveBorderBrushKey}}" >
<TextBlock Text="SystemColors.InactiveBorderBrushKey" />
</Border>
<Border Background="{DynamicResource {x:Static SystemColors.InactiveCaptionBrushKey}}" >
<TextBlock Text="SystemColors.InactiveCaptionBrushKey" />
</Border>
<Border Background="{DynamicResource {x:Static SystemColors.InactiveCaptionTextBrushKey}}" >
<TextBlock Text="SystemColors.InactiveCaptionTextBrushKey" />
</Border>
<Border Background="{DynamicResource {x:Static SystemColors.InfoBrushKey}}" >
<TextBlock Text="SystemColors.InfoBrushKey" />
</Border>
<Border Background="{DynamicResource {x:Static SystemColors.InfoTextBrushKey}}" >
<TextBlock Text="SystemColors.InfoTextBrushKey" />
</Border>
<Border Background="{DynamicResource {x:Static SystemColors.MenuBrushKey}}" >
<TextBlock Text="SystemColors.MenuBrushKey" />
</Border>
<Border Background="{DynamicResource {x:Static SystemColors.MenuBarBrushKey}}" >
<TextBlock Text="SystemColors.MenuBrushKey" />
</Border>
<Border Background="{DynamicResource {x:Static SystemColors.MenuHighlightBrushKey}}" >
<TextBlock Text="SystemColors.MenuHighlightBrushKey" />
</Border>
<Border Background="{DynamicResource {x:Static SystemColors.MenuTextBrushKey}}" >
<TextBlock Text="SystemColors.MenuTextBrushKey" />
</Border>
<Border Background="{DynamicResource {x:Static SystemColors.ScrollBarBrushKey}}" >
<TextBlock Text="SystemColors.ScrollBarBrushKey" />
</Border>
<Border Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" >
<TextBlock Text="SystemColors.WindowBrushKey" />
</Border>
<Border Background="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" >
<TextBlock Text="SystemColors.WindowFrameBrushKey" />
</Border>
<Border Background="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}" >
<TextBlock Text="SystemColors.WindowTextBrushKey" />
</Border>
</StackPanel>
</StackPanel>
</ScrollViewer>
感謝您的幫助
編輯: 這裏是發佈的C#解決方案的VB.NET版本。 您可以綁定到WindowColorBrush屬性設置之類的控制背景顏色在您的WPF風格:
Public Class WindowsBackgroundRetriever
Implements System.ComponentModel.INotifyPropertyChanged
<Runtime.InteropServices.StructLayout(Runtime.InteropServices.LayoutKind.Sequential)> _
Public Structure DWMCOLORIZATIONPARAMS
Public ColorizationColor As UInt32
Public ColorizationAfterglow As UInt32
Public ColorizationColorBalance As UInt32
Public ColorizationAfterglowBalance As UInt32
Public ColorizationBlurBalance As UInt32
Public ColorizationGlassReflectionIntensity As UInt32
Public ColorizationOpaqueBlend As UInt32
End Structure
Private cParams As New DWMCOLORIZATIONPARAMS
<Runtime.InteropServices.DllImport("dwmapi.dll", EntryPoint:="#127")> _
Private Shared Sub DwmGetColorizationParameters(ByRef dp As DWMCOLORIZATIONPARAMS)
End Sub
Private _windowColor As Color
Public Property WindowColor As Color
Get
Return _windowColor
End Get
Set(ByVal value As Color)
_windowColor = value
RaiseEvent PropertyChanged(Me, New System.ComponentModel.PropertyChangedEventArgs("WindowColor"))
End Set
End Property
Private _windowColorBrush As SolidColorBrush
Public Property WindowColorBrush As SolidColorBrush
Get
If _windowColorBrush Is Nothing Then
_windowColorBrush = New SolidColorBrush(WindowColor)
End If
Return _windowColorBrush
End Get
Set(ByVal value As SolidColorBrush)
_windowColorBrush = value
RaiseEvent PropertyChanged(Me, New System.ComponentModel.PropertyChangedEventArgs("WindowColorBrush"))
End Set
End Property
Public Sub New()
DwmGetColorizationParameters(cParams)
Dim r = BitConverter.GetBytes(cParams.ColorizationColor >> 16)
Dim g = BitConverter.GetBytes(cParams.ColorizationColor >> 8)
Dim b = BitConverter.GetBytes(cParams.ColorizationColor)
WindowColor = Color.FromArgb(BitConverter.GetBytes(255)(0), r(0), g(0), b(0))
End Sub
Public Event PropertyChanged(ByVal sender As Object, ByVal e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
End Class
您是否希望在Windows Vista和7中獲取Aero玻璃色調?如果是這樣,你會想看看這個:http://stackoverflow.com/questions/3560890/vista-7-how-to-get-glass-color – BoltClock
是的...在閱讀該鏈接後,我非常氣餒對這個。爲什麼哦爲什麼不能使用普通窗口! – Frinavale
BoltClock,發佈這個答案,我會標記爲這樣。在這個時候,我決定採取不同的方法解決問題。我決定不嘗試將非窗口控件設置爲窗口。相反,我要編寫自己的從Window繼承的Telerik對話框。 – Frinavale