How to create your item in visual stidio?

When working with projects like wpf, is given a lot of freedom to create the interface. Quite often, Nay always, the interface consists of similar elements like: button, TextBox, picture. But sometimes there is a need for frequent use of more complex structures, which is extremely cumbersome. For example, the analogue of list cheackbox's, or sticking slider button. Is it possible to create a feature that will be called more compact code?
September 26th 19 at 07:26
1 answer
September 26th 19 at 07:28
For this you can create a UserControl or CustomControl.
In the first case, you create a UserControl (user control) by adding it to the project as window application. Set up essentially as part of the application window, adding the necessary controls on it and describing logic in the code. After project is compiled, the control will automatically be placed on the toolbar.
For example:
<usercontrol x:class="WpfApplication3.UserControl1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:ignorable="d" d:designheight="300" d:designwidth="300">
<grid>
<grid.rowdefinitions>
<rowdefinition>
<rowdefinition>
</rowdefinition></rowdefinition></grid.rowdefinitions>
<textbox>
 <listbox grid.row="1">
</listbox></textbox></grid>
</usercontrol>


In the second case, you would inherit from the base control and add to the theme of the design and some logic. Menu items are added this type is called a CustomControl or a custom control.
Or through C#:
public MyTextBox : TextBox
{

}


Either via Xaml:
<textbox x:class="WpfApplication1.MyTextBox" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:ignorable="d">

</textbox>

Find more questions by tags User interfaceVisual StudioWPF