Hide controls when it gets outside a canvas/ Silverlight clip example

Hide controls when it gets outside a canvas/ Silverlight clip example

  • Some times when you are using canvas control in silverlight, other controls inside the canvas will went out side,So how to avoid that?
  • For that problem there is a solution in silverlight called Clip property.You can select the size to be visible.

xaml code:

If there is an existing control in you layout that you want to dynamically clip then use its SizeChangedevent. For example lets say you want to clip this Grid
 <Grid SizeChanged="Grid_SizeChanged" Width="50" Height="20">
        <Grid.Clip>
            <RectangleGeometry />
        </Grid.Clip>
        <TextBlock Margin="0 -9 0 0" Text="This is the control went outside the canvas" />
    </Grid>

C# code:

 private void Grid_SizeChanged(object sender, SizeChangedEventArgs e)
    {
        ((RectangleGeometry)((Grid)sender).Clip).Rect = new Rect(0.0, 0.0, e.NewSize.Width, e.NewSize.Height);
    }  

Comments

Popular posts from this blog

Upload Single/Multiple file by using the REST API and jQuery SharePoint 2013

A type named 'SP.Data. could not be resolved by the model error

Add content type to SharePoint List/Library using REST API