Manvinder
Manvinder

Reputation: 4591

User control vs Control Template in WPF

I have recently reviewing someone's code and come across a User Control whose UI is like this screenshot

enter image description here

This control has no code in its code behind file, i am thinking we could move all the xaml code of this user control to a control template and use it whereever required. I want to know if this a good practice and should i do so?

Is their any performance and design benefit of one approach over another?

Upvotes: 4

Views: 1900

Answers (2)

yo chauhan
yo chauhan

Reputation: 12315

Since ultimately this is going to be a UserCotrol,Now suppose some other team working on other module require this control and they want Loaded event of the Datagrid within this Control, Now if you create it as datagrid within usercontrol then they can easily access that datagrid and subscribe Load Event to it. If you will do it in ControlTemplate then it will be difficult if not impossible.

Upvotes: 1

Ouarzy
Ouarzy

Reputation: 3043

I want to know if this a good practice

So first we should define good practice? I will give the agile good practice point of view: do it only if you need it. Thus for you the answer is in your question:

use it whereever required

Is it required in any other place? If so, use a Control Template. If not, use a User Control, which will be more readable for the next developper anyway (Keep It Stupid and Simple).

Upvotes: 1

Related Questions