b

Sunday, 23 December 2012

How do I convert a string value to a SolidColorBrush in WPFand C#


Converting String to Color Object in C# WPF


            String myColor = "Red";
            String xamlString = "<Canvas xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" Background=\""+myColor +"\"/>";
            Canvas c = (Canvas)System.Windows.Markup.XamlReader.Load(xamlString);
            SolidColorBrush mistyRoseBrush = (SolidColorBrush)c.Background;
            Color backColor = mistyRoseBrush.Color;
            
            SolidColorBrush FinalBrush = new SolidColorBrush(backColor );

No comments:

Post a Comment