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

Recommended way to create a window: code-behind vs usercontrol

1 Answer 137 Views
Window
This is a migrated thread and some comments may be shown as answers.
recotech
Top achievements
Rank 1
recotech asked on 18 Feb 2021, 09:07 AM

Hello, i am regulary wondering if there is a recommended way to create a window is: create an usercontrol or create an instance in code-behind? 

The documention gives me the impression that the code-behind is the way to go and the usercontrol is just a work-around, but in most examples the usercontrol method is used.

Or it does not matter at all and one should use the method that fits best at the moment?

 

many greetings :-)

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 22 Feb 2021, 07:05 AM

Hello Sebastian,

You can use whatever approach suits your current needs. The UserControl approach is useful in cases you want to define a complex view directly in the RadWindow control. If you already have your UI defined in a separate UserControl, you can create and open the window in code-behind. However, neither of those approaches is necessary. Go with whatever works for you.

About the help documentation and the UserControl method, I guess you mean the approach where RadWindow is used as the main window of the application. In this case, the StartupUri is removed from App.xaml and the window is opened in code-behind. This is because, RadWindow is not an actual Window control, but a user control internally hosted by a Window. This mean that if you provide the RadWindow's path to the StartupUri, nothing will happen because the WPF framework will expect an object that derives from the native Window. 

I hope this information helps. 

Regards,
Martin Ivanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Window
Asked by
recotech
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or