2010-12-22 71 views
3

我正在開發window phone 7應用程序。我是新來的銀光。在我的應用程序中,我需要一個動態組合框。所以我用下面的代碼如何動態設置combox的Foreground屬性?

ComboBox CurrenciesCombobox = null; 
CurrenciesCombobox = new ComboBox(); 
       CurrenciesCombobox.Name = "CurrencyCombobox"; 
       CurrenciesCombobox.SetValue(Canvas.TopProperty, 10.00); 
       CurrenciesCombobox.SetValue(Canvas.LeftProperty, 10.00); 
       CurrenciesCombobox.Margin = new Thickness(235, 395, 139, 180); 
       //CurrenciesCombobox.Foreground = ; 
       CurrenciesCombobox.ItemsSource = Currencies; 
       CurrenciesCombobox.SelectionChanged += new SelectionChangedEventHandler(CurrenciesCombobox_SelectionChanged); 
       ContentPanel.Children.Add(CurrenciesCombobox); 

在上面的代碼,我不知道如何設置下面的語句的右手邊

CurrenciesCombobox.Foreground = ; 

能否請你告訴我如何設置前景色combobx的屬性? 你能否給我提供任何可以解決上述問題的代碼或鏈接?如果我做錯了什麼,請指導我。

回答

8

要將其設置爲White,使用下面的代碼:

CurrenciesCombobox.Foreground = new SolidColorBrush(Colors.White); 

是相同如下:

CurrenciesCombobox.Foreground = new SolidColorBrush(new Color() 
{ 
    A = 255 /*Opacity*/, 
    R = 255 /*Red*/, 
    G = 255 /*Green*/, 
    B = 255 /*Blue*/ 
}); 

第二條本辦法在這裏提供了更多的靈活性。

還有其他類型的筆刷:Brushes in Silverlight

此外,在使用Windows Phone 7時,應考慮使用主題顏色。看看可用的theme resources

4

嘗試的

CurrenciesCombobox.Foreground = (Brush)Application.Current.Resources["PhoneAccentBrush"]; 

的進一步選擇喜歡這裏詳述

Theme Resources for Windows Phone

CurrenciesCombobox.Foreground = new SolidColorBrush(Colors.Red);