Recommended

Skip Navigation LinksHome / Tips

Tips

+
Page 
Items Resolution

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


    There is a special control in Silverlight responsible for scrolling of content. The full name of this control is System.Windows.Controls.ScrollViewer. You can use it like a regular container by placing all of the content you want to scroll inside of it. The control's properties that worth mentioning are two: HorizontalScrollBarVisibility and VerticalScrollBarVisibility. As you can guess they allow you to control the visibility of the vertical and horizontal scrollbars. The possible values are Auto, Disabled, Hidden and Visible.

    Share


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


    Path is used to specify then name of the property of the underlying object to bind to. Additional you are able to use indirect property targeting to specify a sub-property of a property of the object. Currently it is not possible to bind to indexed properties.

    Xaml

    <TextBlock Text="{Binding Name}"/>
    <TextBlock Text="{Binding Path=Name}"/>
    <TextBlock Text="{Binding Path=Account.OpenDate}"/>
    <TextBlock Text="{Binding Path=Property1.Property2.Property3}"/>

    That's it!

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


    Currently there is no way to do that by using binding. Instead, you can make a List<> and add the values from the enumeration in the list. Then you can use this list as data source.

    C#

    List<Dock> enumDataSource = new List<Dock>() { Dock.Left, Dock.Top, Dock.Right, Dock.Bottom };
    this.lbDock.ItemsSource = enumDataSource;

    where lbDock is of type ListBox.

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

    When the value of a property is changed it should notify the bound objects that the property value has changed. You can do that by implementing changed event.

    C#

     

    public class Client
    {
        private string name;
        public event EventHandler NameChanged;
     
        public string Name
        {
            get
            {
                return this.Name;
            }
            set
            {
                if ( this.name == value )
                    return;
     
                this.name = value;
                this.OnNameChanged( EventArgs.Empty );
            }
        }
     
        protected virtual void OnNameChanged( EventArgs e )
        {
            if ( this.NameChanged != null )
                this.NameChanged( this, e );
        }
    }

     

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

    Share
  • 7 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
  • 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
  • 2 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 the <object> element and insert the bold line bellow.

    HTML

    <object data="data:application/x-silverlight," type="application/x-silverlight-2-b2" width="100%" height="100%"> 
        ...
    element?')" onmouseout="addthis_close()" onclick="return addthis_sendto()">Share
  • 2 comments  /  posted by  Denislav Savkov  on  Aug 29, 2008 (more than a year ago)

    If you have used multiple threads or just timers in your applications, you probably know that if you have to update any user interface, control you should not do it from any other thread but from the one that the control was created from. That is why if your application uses multiple threads, you always have to be aware of what thread you are in.
    In Silverlight invoking a piece of code in the user interface thread can be achieved by using the BeginInvoke method of the System.Windows.Threading.Dispatcher class.

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

    In some scenarios we need to find out what are the objects located at a specific point or in a certain area. In this case we get access to the System.Windows.UIElelement objects using the UIElement.HitTest method. It can test a Rect area or a Point. The return value is a collection of the children in this area arranged from the top element to the bottom.

    C#

    Rect areaInAbsoluteCoordinates = new Rect( areaLeftCoordinate, areaTopCoordinate, areaWidth, areaHeight );
    IEnumerable<UIElement> childrenInArea = panel.HitTest(areaInAbsoluteCoordinates );

    Note! In Silverlight the coordinates for hit testing are the absolute coordinates of the application.

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

    In Silverlight for hit testing are used the absolute coordinates of the application. In case you want to hit test with coordinates relative to a System.Windows.UIElement you need to get the coordinates of the UIElement relative to the application root (i.e. the absolute coordinates of an element ).

    C#

    GeneralTransform generalTransform = uiElement.TransformToVisual( Application.Current.RootVisual);
    Point elementToApplicationRootCoords = generalTransform.Transform( new Point( 0, 0 ) );

    And then add them to the coordinates relative to the element.

    Share

Page 
Help us make SilverlightShow even better. 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 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)