[英]How to set the Foreground property of the combox dynamically?
我正在開發windows phone 7應用程序。 我是銀光的新手。 在我的應用程序中,我需要一個動態組合框。 所以我使用以下代碼
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的Foreground屬性嗎? 能否請您提供我可以解決上述問題的任何代碼或鏈接? 如果我做錯了什么,請指導我。
要將其設置為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
,您應該考慮使用主題顏色。 看看可用的主題資源 。
試試喜歡的
CurrenciesCombobox.Foreground = (Brush)Application.Current.Resources["PhoneAccentBrush"];
此處詳述的其他選項
要么
CurrenciesCombobox.Foreground = new SolidColorBrush(Colors.Red);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.