Skip Navigation LinksHome / Tips / General

General

+
Page 
Items Resolution

  • 4 comments  /  posted by  Nikolay Raychev  on  Apr 02, 2009 (11 months ago)
    Silverlight 3 comes with two built in Pixel Shaders:

    We have the following image:



    We want to blur it:

    <Image Width="300"   
        Source="http://terraristic.net/photos/  
        Brachypelma_albiceps/Brachypelma_albiceps_1.jpg"> 
        <Image.Effect>
            <BlurEffect Radius="8"></BlurEffect>
        </Image.Effect>
    </Image> 

    We have the following result:



    Note the Radius parameter.
    Share


  • 1 comments  /  posted by  Nikolay Raychev  on  Apr 02, 2009 (11 months ago)
    In Silverlight 3 you can make multiple selections in a ListBox. You just need to set the SelectionMode parameter:

    <ListBox Margin="5" x:Name="lbTasks"   
        ItemsSource="{Binding Tasks, ElementName=MainPageView}"   
        SelectionMode="Multiple">  
        <ListBox.ItemTemplate> 
            <DataTemplate> 
                <StackPanel Orientation="Horizontal" Margin="2">  
                    <TextBlock FontWeight="Bold" FontSize="13"   
                        Foreground="#ff006882" Text="{Binding Text}">  
                    </TextBlock> 
                </StackPanel> 
            </DataTemplate> 
        </ListBox.ItemTemplate> 
    </ListBox> 

    You have 3 options for the SelectionMode:
    • Single - you can select only one item.
    Share
  • 1 comments  /  posted by  Nikolay Raychev  on  Mar 25, 2009 (11 months ago)
    It's very easy to style the caret in Silverlight 3. Look at that huge TextBox with a caret in the rainbow colors:



    You just need to set the CaretBrush property:

    <TextBox FontSize="50" Width="100" Height="80">  
        <TextBox.RenderTransform> 
            <ScaleTransform ScaleX="6" ScaleY="1"/>  
        </TextBox.RenderTransform> 
        <TextBox.CaretBrush>
            <LinearGradientBrush x:Name="backgroundLinearGradientBrush"
                MappingMode="RelativeToBoundingBox"
                    StartPoint="0,0" EndPoint="0,1">
                <LinearGradientBrush.GradientStops>
                    <GradientStop Color="Red" Offset="0" />
                    <GradientStop Color="Orange" Offset="0.167" />
                    <GradientStop Color="Yellow" Offset="0.333" />
                    <GradientStop Color="Green" Offset="0.5"/>
                    <GradientStop Color="Blue" Offset="0.667" />
                    <GradientStop Color="Indigo" Offset="0.833" />
                    <GradientStop Color="Violet" Offset="1" />
                </LinearGradientBrush.GradientStops>
            </LinearGradientBrush>
        </TextBox.CaretBrush> 
    </TextBox> 

    You can use any Silverlight supported Brush.
    Share
  • 2 comments  /  posted by  Emil Stoychev  on  Mar 23, 2009 (11 months ago)

    Silverlight 3 enables property binding to CLR objects and other UI components via XAML – UI to UI binding. It is useful in a lot of scenarios and saves time for both developers and designers.

    Example

    Get Microsoft Silverlight

    Download source code

    Syntax

    {Binding Value, ElementName=MySlider}

    where Value is property of a CLR object and MySlider is the name of this object

    Hope that helps!

    Share
  • 2 comments  /  posted by  Martin Mihaylov  on  Nov 28, 2008 (more than a year ago)

    Have you ever noticed that the MouseLeftButtonDown and MouseLeftButtonUp events are not fired when a Silverlight button is clicked? The reason for this is that the button handles these two events itself by overriding the OnMouseLeftButtonDown  and the OnMouseLeftButtonUp  handlers. In the OnMouseLeftButtonDown  override the Click event is raised and the MouseLeftButtonDown event is marked as handled so it couldn't bubble in the visual tree. The OnMouseLeftButtonUp  override also marks the MouseLeftButtonUp  as handled.

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

    When using the object element to display our Silverlight application, we can use parameters to configure it (source, onerror, background, minRuntimeVersion and etc.):

    <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
        <param name="source" value="ClientBin/Issues.xap"/>
        <param name="onerror" value="onSilverlightError" />
        <param name="background" value="white" />
        <param name="minRuntimeVersion" value="2.0.31005.0" />
        <param name="autoUpgrade" value="true" />
        <a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;">
             <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/>
        </a>
    </object>

    Some of them are predefined in the automatically created TestPages, but we can also add additional parameters like initParams, onload and etc.

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

    Just use the following line.

    C#

    Application.Current.Host.Content.IsFullScreen = true;   

    Entering full-screen mode in Silverlight has some restrictions. To ensure that it is initiated by the user entering full-screen mode is possible only in response to one of these input events: MouseLeftButtonDown. MouseLeftButtonUp, KeyDown, KeyUp.

    That's it!

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

    The callback function of a routed event has the second parameter e of type RoutedEventArgs or its inheritor. The Source property of this parameter holds reference to the object that raised the event. In contrast to that the sender parameter holds reference to the object where the event handler was invoked.

    C#

    void RoutedEventRaised( object sender, RoutedEventArgs e )
    {
        object source = e.Source;
    }

    That's it!

    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
  • 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

Page