title: How to get System.Windows.Media.Color From From HEX Windows 8 Application
body: <p>I want to set Border background color from web color value in my <strong>windows 8 mobile application .</strong></p>
  
  <p>I found one method that convert hex to Argb but its not working for me ..</p>
  
  <pre><code>  private System.Windows.Media.Color FromHex(string hex)
          {
              string colorcode = hex;
              int argb = Int32.Parse(colorcode.Replace("#", ""), System.Globalization.NumberStyles.HexNumber);
              return System.Windows.Media.Color.FromArgb((byte)((argb &amp; -16777216) &gt;&gt; 0x18),
                                    (byte)((argb &amp; 0xff0000) &gt;&gt; 0x10),
                                    (byte)((argb &amp; 0xff00) &gt;&gt; 8),
                                    (byte)(argb &amp; 0xff));
  
  
          }
  </code></pre>
  
  <p>I am using above method like..</p>
  
  <pre><code>     Border borderCell = new Border();
       var col = FromHex("#DD4AA3");
       var color =new System.Windows.Media.SolidColorBrush(col);
       borderCell.Background = color;
  </code></pre>
  
  <p>But if I pass color hex value like below</p>
  
  <pre><code>            var col = FromHex("#FFEEDDCC");
  </code></pre>
  
  <p>its works fine but it not work on my hex color value.</p>
  
  <p>Before posting this question I go thru this stack answer.
  <a href="https://stackoverflow.com/questions/2109756/how-to-get-color-from-hexadecimal-color-code-using-net">How to get Color from Hexadecimal color code using .NET?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/2395438/convert-system-drawing-color-to-rgb-and-hex-value">Convert System.Drawing.Color to RGB and Hex Value</a></p>