Answered by:
Set Foreground Color and Using System Resources

Question
-
Hi,
I am attempting to set the foreground color on a button using C#, but I have not been able to find a way to do this (even the MS document does not work). Here is the code I am attempting to use:
ItemHDSCustodySignBtn.Foreground = Brushes.Blue;
This code is invalid. Additionally, I would prefer to use the exact numeric value rather than the string name of the color.
My second problem is how I can apply a style to my button. I have a style that is accessible throughout the app, however, I cannot find documentation anywhere in how to do this in C# rather than XAML.
Thanks for your help with this.
Tuesday, June 24, 2014 5:48 PM
Answers
-
Hi JB,
Problem one:
ItemHDSCustodySignBtn.Foreground = new SolidColorBrush(Colors.Blue);
When you want to use the exact numeric value, you could either use the static Color.FromArgb-Method to create the color object or you can set the A R G B-Properties manually and for example parse a hex-string like it is done here:
http://stackoverflow.com/questions/16733182/how-to-convert-hexdecimal-code-to-color-in-windows-8
Problem two:
WinRT doesn't contain a FindResource-Method. But you could still grab resources and so your still:
Thomas Claudius Huber
"If you can't make your app run faster, make it at least look & feel extremly fast"
My latest app: The "Womanizer" :-)
twitter: @thomasclaudiush
homepage: www.thomasclaudiushuber.com
author of: ultimate Windows Store Apps handbook | ultimate WPF handbook | ultimate Silverlight handbook- Marked as answer by Anne Jing Wednesday, June 25, 2014 2:11 AM
Tuesday, June 24, 2014 6:56 PM -
Hi,
Margin properties are set using a new Thickness created with the uniform-value constructor:
DeptStackPanel.Margin = new Thickness(10);
Please refer to the link below:
http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.frameworkelement.margin.aspx
In XAML there is no margin-top property, but in Html development,you can use it:
http://msdn.microsoft.com/en-us/library/windows/apps/hh996904.aspx
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.- Marked as answer by Anne Jing Thursday, July 3, 2014 7:44 AM
Wednesday, June 25, 2014 2:11 AM
All replies
-
Hi JB,
Problem one:
ItemHDSCustodySignBtn.Foreground = new SolidColorBrush(Colors.Blue);
When you want to use the exact numeric value, you could either use the static Color.FromArgb-Method to create the color object or you can set the A R G B-Properties manually and for example parse a hex-string like it is done here:
http://stackoverflow.com/questions/16733182/how-to-convert-hexdecimal-code-to-color-in-windows-8
Problem two:
WinRT doesn't contain a FindResource-Method. But you could still grab resources and so your still:
Thomas Claudius Huber
"If you can't make your app run faster, make it at least look & feel extremly fast"
My latest app: The "Womanizer" :-)
twitter: @thomasclaudiush
homepage: www.thomasclaudiushuber.com
author of: ultimate Windows Store Apps handbook | ultimate WPF handbook | ultimate Silverlight handbook- Marked as answer by Anne Jing Wednesday, June 25, 2014 2:11 AM
Tuesday, June 24, 2014 6:56 PM -
Thanks for your reply. You solved my issues perfectly.
On another note, do you know how I can retrieve a value (such as a margin) set in the XAML? I want to adjust it programmatically in the back .cs file. (Ex. get the height and change it)
And lastly, does Windows have a nonabbreviated version of margins? Instead of combining, let's say I just want to adjust the top margin. Is there any kind of margin-top tag I can use instead?
Thanks so much for your help.
Tuesday, June 24, 2014 8:15 PM -
Hi,
Margin properties are set using a new Thickness created with the uniform-value constructor:
DeptStackPanel.Margin = new Thickness(10);
Please refer to the link below:
http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.frameworkelement.margin.aspx
In XAML there is no margin-top property, but in Html development,you can use it:
http://msdn.microsoft.com/en-us/library/windows/apps/hh996904.aspx
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.- Marked as answer by Anne Jing Thursday, July 3, 2014 7:44 AM
Wednesday, June 25, 2014 2:11 AM