(X) Hide this Upcoming webinar by Brian Noyes: Querying and Updating Data From Silverlight Clients with WCF RIA Services. February 2nd, 10 am PST (see your local time)
Full webinar info | Register | Read WCF RIA Services Article series by Brian Noyes
Become a member to receive all webinar news by email, or follow all webinar news on Twitter | Facebook | LinkedIn
Skip Navigation LinksHome / Tips

Tips

+
Page 
  • 1
  • 2
  • 3
  • ...
  • 7
Next
Items Resolution

  • 11 comments  /  posted by  Emil Stoychev  on  Mar 23, 2009 (more than a year ago)

    Like in CSS you can now cascade styles in Silverlight 3 too. You can append and/or override values by basing one style on another. In this way you can built a powerful and reusable set of styles to apply in your Silverlight applications.

    Syntax

    Style cascading is accomplished by using the new BasedOn attribute of the Style class.

       1: <Style x:Name="Headline" TargetType="TextBlock">
       2:     <Setter Property="FontFamily" Value="Verdana" />
       3:     <Setter Property="FontSize" Value="14" />
       4: </Style>
       5: <Style x:Name="ImportantHeadline" TargetType="TextBlock" 
       6:     BasedOn="{StaticResource Headline}">
       7:     <Setter Property="Foreground" Value="Red" />
       8: </Style>        
       9: <Style x:Name="HomePageHeadline" TargetType="TextBlock" 
      10:     BasedOn="{StaticResource Headline}">
      11:     <Setter Property="FontSize" Value="18" />
      12: </Style>

    Here we have a base style Headline that targets TextBlock elements and defines values for FontFamily and FontSize.

    Share


  • 10 comments  /  posted by  sam  on  Mar 24, 2010 (10 months ago)

     Sample RSS Feed application using Windows Phone 7 Series SDK.

    Shows RSS feed title list from http://www.visitmix.com/RSS 

    Article details showed in WebBrowser control based on user selection in the list.

     RSS app code 

    Share
  • 10 comments  /  posted by  Denislav Savkov  on  Sep 02, 2008 (more than a year ago)

    Sometimes you might need to handle the application exit event of a Silverlight application in order to logout, clear or perform any other operations required by your internal logic. Exactly for this reason there is an Exit event located in your project application class that directly derives from System.Windows.Application. In most cases the name of this class is App and you can access its Exit event like this:

    C#

       App.Current.Exit += new EventHandler( ApplicationExit );

    That's it!

    Share
  • 10 comments  /  posted by  Ivan Dragoev  on  Sep 02, 2008 (more than a year ago)
    Tags: Silverlight , ScrollViewer , ItemsControl

    To add scrollbars to ItemsControl you have to modify the control template and to add ScrollViewer for the ItemsPresenter.

    Xaml

    <ItemsControl >
    <
    ItemsControl.Template>
    <
    ControlTemplate>
    <
    ScrollViewer x:Name="ScrollViewer" Padding="{TemplateBinding Padding}">
    <
    ItemsPresenter />
    </
    ScrollViewer>
    </
    ControlTemplate>
    </
    ItemsControl.Template>
    </
    ItemsControl>

     

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

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

    Xaml

    <Rectangle x:Name="MyRect" Width="100" Height="100">
        <Rectangle.Fill>
            <LinearGradientBrush StartPoint="0,0" EndPoint="1,1" >
                <GradientStop Color="Yellow" Offset="0.2"></GradientStop>
                <GradientStop Color="Orange" Offset="0.5"></GradientStop>
                <GradientStop Color="Red" Offset="0.8"></GradientStop>
            </LinearGradientBrush>
        </Rectangle.Fill>
    </Rectangle>

    C# 

    LinearGradientBrush gradient = new LinearGradientBrush();
    gradient.StartPoint = new Point( 0, 0 );
    gradient.EndPoint = new Point( 1, 1 );
     
    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;

    We define the gradient and set its StartPoint and EndPoint properties.

    Share
  • 8 comments  /  posted by  Denislav Savkov  on  Aug 29, 2008 (more than a year ago)

    INotifyPropertyChanged interface is used to notify that a property has been changed and thus to force the bound objects to take the new value.

    C#

    public class Client : INotifyPropertyChanged
    {
        private string name;
        public event PropertyChangedEventHandler PropertyChanged;
     
        public string Name
        {
            get
            {
                return this.Name;
            }
            set
            {
                if ( this.name == value )
                    return;
     
                this.name = value;
                this.OnPropertyChanged( new PropertyChangedEventArgs( "Name" ) );
            }
        }
     
        protected virtual void OnPropertyChanged( PropertyChangedEventArgs e )
        {
            if ( this.PropertyChanged != null )
                this.PropertyChanged( this, e );
        }
    }

    Note that the value is changed only if the new value is different.

    Share
  • 7 comments  /  posted by  Denislav Savkov  on  Sep 03, 2008 (more than a year ago)

    Yes, that is right, there is no Label control in Silverlight. Instead you should use the new control System.Windows.Controls.TextBlock. Keep in mind that it can display only text, no images or other type of content, just text.

    Xaml

    <TextBlock x:Name="statusText" Text="Active" TextWrapping="Wrap" TextAlignment="Left" VerticalAlignment="Center"/>

    C#

    TextBlock statusText = new TextBlock();
    statusText.Text = "Active";
    statusText.TextWrapping = TextWrapping.Wrap;
    statusText.TextAlignment = TextAlignment.Left;
    statusText.VerticalAlignment = VerticalAlignment.Center;

    That's it!

     

    Share
  • 6 comments  /  posted by  Denislav Savkov  on  Aug 29, 2008 (more than a year ago)

    If you want to pass initialize parameters to Silverlight application from an HTML/ASPX page, you have to find the place where your Silverlight control is inserted into the page using ASP.NET 3.5 Silverlight control and insert the InitParameters attribute as shown in the code snippet.

    HTML

    <asp:Silverlight ....
    Share
  • 6 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
  • 6 comments  /  posted by  Denislav Savkov  on  Sep 16, 2008 (more than a year ago)

    Some of the new features in C# 3.0 allow you to write shorter code that is easier to read and maintain. The following code couples have the same results.

    • Short syntax for object initialization initialization.

      C#

       

      ObjectType objectName = new ObjectType();
      objectName.PropertyName = newValue;
      objectName.PropertyName2 = newValue2;
       

       

      C#

      ObjectType objectName = new ObjectType(){ PropertyName = newValue, PropertyName2 = newValue2 };
    • Syntaxt for anonymous types

    C#

    SomeVeryLongNameOfType objectName = new SomeVeryLongNameOfType();

    C#

    var objectName = SomeVeryLongNameOfType();
    • Short syntax for collection initialization

    C#

    CollectionType collectionName = new CollectionType();
    collectionName.Add( newItem1 );
    ..
    Share

Page 
  • 1
  • 2
  • 3
  • ...
  • 7
Next