如何动态设置combox的Foreground属性?(How to set the Foreground property of the combox dynamically?)

编程入门 行业动态 更新时间:2024-10-25 00:32:10
如何动态设置combox的Foreground属性?(How to set the Foreground property of the combox dynamically?)

我正在开发window 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属性吗? 你能否给我提供任何可以解决上述问题的代码或链接? 如果我做错了什么,请指导我。

I am developing window phone 7 application. I am new to the silverlight. In my application I need a dynamic combobox. So I am using the following code

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);

In the above code I am unaware of how to set the right hand side of the following statement

CurrenciesCombobox.Foreground = ;

Can you please tell me how to set the Foreground property of the combobx ? Can you please provide me any code or link through which I can resolve the above issue ? If I am doing anything wrong then please guide me.

最满意答案

要将其设置为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 ,您应该考虑使用主题颜色。 看看可用的主题资源 。

To set it to White, use following code:

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

which is same as following:

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

Second approach here provides more flexibility.

There are other types of Brushes as well: Brushes in Silverlight.

Also, while working with Windows Phone 7, you should consider using theme colors. Take a look at available theme resources.

更多推荐

本文发布于:2023-08-04 09:53:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1415141.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   动态   combox   dynamically   Foreground

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!