Recommended

Skip Navigation LinksHome / Tips

Tips

+
Page 
Items Resolution

  • 1 comments  /  posted by  Martin Mihaylov  on  Sep 11, 2008 (more than a year ago)

    If you want to add a tooltip to a control you must first check if it allows the ToolTipService namespace. If yes, you can add the tooltip the following way:

    Xaml

    <Button x:Name="MyButton" Content="Hello!" Width="50" Height="30">
        <ToolTipService.ToolTip>
            <TextBlock x:Name="ToolTip" Text="Click me!"></TextBlock>
        </ToolTipService.ToolTip>
    </Button>

    C#

    ToolTipService.SetToolTip( MyButton, new TextBlock() { Text = "Click me!" } );

    You can also use another control instead of TextBlock, for example Image control or Rectangle control.

    Share


  • 2 comments  /  posted by  Ilia Iordanov  on  Sep 10, 2008 (more than a year ago)

    Probably the first most important thing to mention here is that only inheritors of System.Windows.DependencyObject can be extended with attached properties. This is needed because either to set or to get value for a specific attached property, you need to use the methods SetValue and GetValue which are defined in the DependencyObject class.
    When you declare an attached property, many advantages from the dependency properties model are coming out of the box for you such as caching, data binding, default values, expressions, styling, property invalidation and more.

    Share
  • 3 comments  /  posted by  Ilia Iordanov  on  Sep 09, 2008 (more than a year ago)

    Probably the first most important thing to mention here is that only inheritors of System.Windows.DependencyObject can be extended with dependency properties. This is needed because either to set or to get value for a specific dependency property, you need to use the methods SetValue and GetValue which are defined in the DependencyObject class.
    When you declare a dependency property, many advantages are coming out of the box for you such as caching, data binding, default values, expressions, styling, property invalidation and more.

    Share
  • 4 comments  /  posted by  Martin Mihaylov  on  Sep 09, 2008 (more than a year ago)

    If you're not familiar with the value converters read this. The methods generated by the VisualStudio when creating a custom class that implements System.Windows.Data.IValueConverter have several arguments. One of them is of type object and is called parameter.

     

    public class DateTimeConverter : System.Windows.Data.IValueConverter
    {
        public object Convert( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture )...
       
        public object ConvertBack( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture )...
    }

     

    In this example we bind to an object of type Book:

    public class Book
    {
        public DateTime PublishDate { get; set; }
    }

    We can pass this argument from the code or from the Xaml.

    Share
  • 0 comments  /  posted by  Martin Mihaylov  on  Sep 09, 2008 (more than a year ago)

    In order to invoke a JavaScript function  we must access the DOM from the Silverlight application. This can be done with the help of the System.Windows.Browser.HtmlPage class. Here it is how it's done:

    HtmlPage.Window.Invoke( "Function_Name", new object[] { //Array of paramaters that must be passed to the function } );

    We call the Invoke method of the Window property, which takes the name of the function and an array of its arguments as parameters.

    That's it!

    Share
  • 1 comments  /  posted by  Martin Mihaylov  on  Sep 09, 2008 (more than a year ago)

    First let's explain what the convertors can be used for. Imagine you bind to an object's property, but the property is not formatted to your likings. In this case you can use converters. For example we bind to the PublishDate property of a Book object and want the date to be formatted like this - "dd MMM, yyyy".

    Book myBook = new Book();
    myBook.PublishDate = DateTime.Now;

    First let's create our converter.

    Share
  • 0 comments  /  posted by  Martin Mihaylov  on  Sep 09, 2008 (more than a year ago)

    If you want to bind an object's property to a control's property you can do it the following way.First let's create the object taht the control will bind to (for example a class called Book):

    public class Book
    {
        public string Title { get; set; }
        public string Description { get; set; }
    }

    After that define your control in the Xaml (a TextBlock for example):

    <TextBlock x:Name="MyText" Text="{Binding Title}"></TextBlock>

    Using the binding syntax we bind the Text proeprty to the Title property of the Book object. In the codebehind we create an instance of the Book object and set the DataContext of the control to it:

    Book myBook = new Book();
    myBook.Title = "Silverlight book";
    myBook.Description = "A book about Silverlight.
    Share
  • 0 comments  /  posted by  Ilia Iordanov  on  Sep 08, 2008 (more than a year ago)

    If you need to create a XAP file you can do it very easily by using Chiron. Chiron is a tool that produces Silverlight application packages (XAPs) for applications using Dynamic Language Runtime (DLR) based languages. The main usage of Chiron is to run as a localhost web-server, and it will automate the XAP file creation with every web-request. Moreover you can manually generate and save XAP file to the disc by running command like:

    > Chiron.exe /directory:MyApp\app /zipdlr:app.xap

    If Chiron is installed it can be found in the following folder 'C:\Program Files\Microsoft SDKs\Silverlight\v2.0\Tools'.

    Share
  • 0 comments  /  posted by  Martin Mihaylov  on  Sep 07, 2008 (more than a year ago)

    A definition of a color in hexidecimal format looks like this: #000000 for black and #ffffff for white. The first two symbols represent the value for red, the second two - for green and the last two - for blue. (If you're not familiar with the Hexidecimal numeral system take a look at this.) Changing these values we can get every color we like. But as you probably know the colors in Silverlight have not only Red, Green and Blue attributes but also an Alpha attribute which determines the transparency of the color.In order to use the Alpha attribute of the color we add two more digits at the start - #00000000 for black with 0% opacity (full transparency) and #ff000000 for black with 100% opacity (no transparency).

    Share
  • 1 comments  /  posted by  Martin Mihaylov  on  Sep 07, 2008 (more than a year ago)

    Here is an example of how to use a RadialGradient Brush to fill a rectangle for example:

    <Rectangle x:Name="MyRect" Width="100" Height="100">
        <Rectangle.Fill>
            <RadialGradientBrush Center="0.5,0.5" RadiusX="0.5" RadiusY="0.5" GradientOrigin="0.5,0.5">
                <GradientStop Color="Yellow" Offset="0.3"></GradientStop>
                <GradientStop Color="Orange" Offset="0.8"></GradientStop>
                <GradientStop Color="Red" Offset="1"></GradientStop>
            </RadialGradientBrush>
        </Rectangle.Fill>
    </Rectangle>

    C#

    RadialGradientBrush gradient = new RadialGradientBrush();
    gradient.Center = new Point( 0.5, 0.5 );
    gradient.GradientOrigin = new Point( 0.5, 0.5 );
    gradient.RadiusX = 0.5;
    gradient.RadiusY = 0.5;
     
    GradientStop color1 = new GradientStop();
    color1.Color = Colors.Yellow;
    color1.Offset = 0.2;
    gradient.GradientStops.Add( color1 );
     
    GradientStop color2 = new GradientStop();
    color2.Color = Colors.Orange;
    color2.Offset = 0.5;
    gradient.GradientStops.Add( color2 );
     
    GradientStop color3 = new GradientStop();
    color3.Color = Colors.Red;
    color3.Offset = 0.8;
    gradient.GradientStops.Add( color3 );
     
    MyRect.Fill = gradient;

    First we define the RadialGradientBrush and set its Center, GradientOrigin, RadiusX and RadiusY properties.

    Share

Page 
Help us make SilverlightShow even better and win a free t-shirt. Whether you'd like to suggest a change in the structure, content organization, section layout or any other aspect of SilverlightShow appearance - we'd love to hear from you! Need a material (article, tutorial, or other) on a specific topic? Let us know and SilverlightShow content authors will work to have that prepared for you. (hide this)