This is a migrated thread and some comments may be shown as answers.

Pass Values To User Control

1 Answer 94 Views
Window
This is a migrated thread and some comments may be shown as answers.
Don
Top achievements
Rank 1
Don asked on 06 Nov 2009, 03:51 PM
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

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Evan
Telerik team
answered on 13 Nov 2009, 04:01 PM
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.
Tags
Window
Asked by
Don
Top achievements
Rank 1
Answers by
Evan
Telerik team
Share this question
or