Results 1 to 4 of 4

Thread: Color management tips for Silverlight 3.0

  1. #1
    Join Date
    May 2008
    Posts
    188

    Color management tips for Silverlight 3.0

    The use of color in Silverlight 3.0 is usually made directly into the file. Xaml mainly due to the presence dell intellisense, which allows the choice of its friendly name of each color available, within the properties of the elements of type Color visual part of our application. Each color has its name and its hexadecimal code, just like html. In this table you can find a complete list of colors available:



  2. #2
    Join Date
    May 2008
    Posts
    188

    Re: Color management tips for Silverlight 3.0

    Side code, however, we do not have the same ease of choice. This is because the Color class has only a default constructor without parameters. This means that simply wanting to use it, then we must make use of the property A, R, G and B.
    Code:
      Color c = new Color ();
    
      cA = 255; cR = 0; cG = 0, cB = 0;
    
      SolidColorBrush brush = new SolidColorBrush (c);
    As you can see is quite inconvenient. Given this lack, however, have included the Colors class, which allows you to instantiate a color from a predefined set of basic colors.

    Code:
      Color c = Colors.Black;
    
      SolidColorBrush brush = new SolidColorBrush (c);
    The fact is that the set is made up of just a few colors, but the activities are the answer faster. The same mechanism also applies to the class SystemColors, which contains a small list of colors associated with the operating system.

    Code:
      Color c = SystemColors.ControlColor;
    
      SolidColorBrush brush = new SolidColorBrush (c);
    Another option we have, instead, to instantiate a new color is to use the method FromArgb () just more of the Color class, respectively, passing the value for the alpha channel, the value for red, green, and the blue.

    Code:
      Color c = Color.FromArgb (255, 255, 255, 255);
    
      SolidColorBrush brush = new SolidColorBrush (c);

  3. #3
    Join Date
    May 2008
    Posts
    188

    Re: Color management tips for Silverlight 3.0

    Even though this is quite inconvenient, as we always know the values to be given to property R, G and B for the construction of the color we need. As for creating a new instance of the Color class from a color expressed in hexadecimal, unfortunately does not have the Silverlight class ColorTranslator. NET Framework inside its libraries, but nothing prevents us from creating a little method to convert the hex values in bytes.

    Code:
      public static Color GetColorFromHexadeciaml (string color)
    
      {
    
      Color.FromArgb (
    
      Convert.ToByte (color.Substring (1, 2), 16)
    
      Convert.ToByte (color.Substring (3, 2), 16)
    
      Convert.ToByte (color.Substring (5, 2), 16)
    
      Convert.ToByte (color.Substring (7, 2), 16)
    
      );
    
      }

  4. #4
    Join Date
    May 2008
    Posts
    188

    Re: Color management tips for Silverlight 3.0

    If, however, we are so lazy to want to create color side code, using its name firendly, we use a pretty neat trick, but for which no guarantees regarding the performance in case of intensive use. Through the class XamlReader you can create a new object by passing a string that represents the syntax in a file. Xaml, then we create an element of type and color using the Line Color LightBlue, as if he were doing all 'Internal text editor for Visual Studio, we are then able to retrieve the instance of the Color Fill property, which we exploited in the XAML.

    Code:
      private Color FromKnownColor (string colorName)
    
      {
    
      Line line = (Line) XamlReader.Load ("<Line" +
    
      "Xmlns = \" http://schemas.microsoft.com/winfx/2006/xaml/presentation \ "" +
    
      "Xmlns: x = \" http://schemas.microsoft.com/winfx/2006/xaml \ "" +
    
      "Fill = \" "+ colorName +" \ "/>");
    
      return (Color) line.Fill.GetValue (SolidColorBrush.ColorProperty);
    
      }
    
      Color c = FromKnownColor ("LightBlue");
    You will agree with me that, compared to the rest, this is the most convenient solution for using the colors using its friendly name, side code.

Similar Threads

  1. Color Management Support in Opera
    By Chachhi in forum Technology & Internet
    Replies: 5
    Last Post: 06-11-2011, 10:51 PM
  2. Battery management tips for nokia
    By Tikoo in forum Portable Devices
    Replies: 7
    Last Post: 28-10-2011, 04:16 AM
  3. Monitor ICC Profile (color management)
    By dONGsUN in forum Portable Devices
    Replies: 5
    Last Post: 12-09-2010, 07:03 AM
  4. HDRI & IBL and color management
    By Dewei in forum Windows Software
    Replies: 5
    Last Post: 18-05-2010, 06:21 AM
  5. Color Management: Vista won't hold a custom ICC profile
    By globetrotter in forum Vista Help
    Replies: 7
    Last Post: 17-09-2009, 05:11 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,043,451.75901 seconds with 16 queries