Pass Values To User Control

2 posts, 0 answers
  1. Don
    Don avatar
    40 posts
    Member since:
    Apr 2009

    Posted 06 Nov 2009 Link to this post

    I Have a user control hosted in a RadWindow. I need to set properties on the user control when the window opens. I also then need to read those values when the dialog closes. Here is how I have the window and user control defined.
     
                <telerikNavigation:RadWindow x:Name="SwimLanesWindow" WindowStartupLocation="CenterOwner"   
                     ResizeMode="CanResize" Opened="OnSwimLanesOpened" Closed="OnSwimLanesClosed" > 
                    <local:SwimLaneDefinition /> 
                </telerikNavigation:RadWindow> 
     

    How do I set the properties on the user control or is there a better way to handle this?

    Don Miller

     

     

     

     

  2. Evan
    Admin
    Evan avatar
    13 posts

    Posted 13 Nov 2009 Link to this post

    Hi Don,

    There are a few ways that you can handle this.  One would be to handle the RadWindow.Opened event in order to set properties:

    private void xRadWindow_Opened(object sender, RoutedEventArgs e)
    {
        // xNameText, xCompanyText, and xRadDatePicker are controls
        //   that sit in the OtherControl user control
        OtherControl oc = xRadWindow.Content as OtherControl;
        oc.xNameText.Text = "Enter a name";
        oc.xCompanyText.Text = "Enter a company";
        oc.xRadDatePicker.SelectedDate = DateTime.Today; ;
    }

    Another would be to have the UserControl grab items from the main page in its Loaded event.  There are a few options to do this, but one way might be as follows:

    void OtherControl_Loaded(object sender, RoutedEventArgs e)
    {
        MainPage p = Application.Current.RootVisual as MainPage;
        xNameText.Text = p.tempCustomer.customerName;
        xCompanyText.Text = p.tempCustomer.customerCompany;
        xRadDatePicker.SelectedDate = p.tempCustomer.customerDate;
    }

    Passing info back would be a similar process.  Since the entire app is sitting on the client, you could grab a reference to the user control (since it is the RadWindow.Content) and take values directly from it:

    private void xRadWindow_Closed(object sender, Telerik.Windows.Controls.WindowClosedEventArgs e)
    {
        OtherControl oc = xRadWindow.Content as OtherControl;
        tempCustomer.customerName = oc.xNameText.Text;
        tempCustomer.customerCompany = oc.xCompanyText.Text;
        tempCustomer.customerDate = ((DateTime)oc.xRadDatePicker.SelectedDate);
    }

    And just for reference, tempCustomer is from a generic class I use for testing, Customer, which has these three items: customerName, customerCompany, and customerDate.

    Let us know if this helps.  There are quite a few ways that this could be handled, but I wanted to give you a few options on how this could be done. 

    All the best,
    Evan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. DevCraft banner
Back to Top