2010-10-05 144 views
1

在我的小型WPF程序中,我希望在消息框中單擊鼠標時顯示客戶區的「背景顏色」的名稱....我怎樣才能做它?如何獲取WPF背景的顏色

系統:Win7(32位)/ VS2008

謝謝。

+1

客戶區.... – 2010-10-05 17:38:26

回答

9

您需要獲取要獲取其顏色的元素的背景對象。在你的鼠標點擊事件中這樣做:

注意:您必須檢查哪種筆刷類型,基本上SolidColorBrush只會真正適用,因爲漸變不會是簡單的顏色。

示例: Brush backgroundColor = LayoutRoot.Background;

 if (backgroundColor is SolidColorBrush) 
     { 
      string colorValue = ((SolidColorBrush)backgroundColor).Color.ToString(); 
     }