SIGN UP MEMBER LOGIN:    
ARTICLE

Closing a UserControl on Button Click in Silverlight

Posted by Santhosh Kumar Articles | Silverlight with C# March 01, 2012
In this article, we are going to see how to close a user control by clicking a button inside it.
Reader Level:

Closing a UserControl on Button Click in Silverlight

In this article, we are going to see how to close a user control by clicking a button inside it.

We had a scenario when using a telerik radgridview, we wanted to customize a filter for a date field. So we created a user control having 2 date pickers to select items within the range. But we are not able to close it. So I tried many things to close the user control, but we were not able to. Finally we came up with a solution after Googling for many hours which I am going to explain here. This is not only limited with customizing filter which I did it for my work, anyone can use this to close a UserControl in Silverlight by a button click.

2111.jpg

In my user control, I added a button as below in XAML.

<StackPanel Grid.Row="0" Grid.Column="3">

    <Button Style="{StaticResource CloseButton}" Width="13" Height="13" Margin="30,0,0,0" Padding="0,0,0,0"
          
 FontSize="9" Content="X" Click="Button_Click" x:Name="btnClose" VerticalContentAlignment
="Top" />

</StackPanel>


In the button click event, I have the following code which will close the user control:

private void Button_Click(object sender, RoutedEventArgs e)

{

        this.IsActive = false;

        var popup = btnClose.ParentOfType<System.Windows.Controls.Primitives.Popup>();

        if (popup != null)

        {

            popup.IsOpen = false;

        }

}

Login to add your contents and source code to this article
share this article :
post comment
 

Thanks for this article.

Posted by Arjun Panwar Mar 02, 2012

its very helpful article..keep it up...

Posted by Sanjoli Gupta Mar 01, 2012

Its a very nice and useful article.

Posted by Monika Arora Mar 01, 2012
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Become a Sponsor