Answer the question
In order to leave comments, you need to log in
How to create custom element in visual stidio?
When working with projects like wpf, a lot of freedom is given to create an interface. Quite often, and rather even always, the interface consists of the same type of elements such as a button, a text field, a picture. But sometimes there is a need for frequent use of more complex structures, which are extremely cumbersome. For example, an analogue of the list of checkboxes, or a sticky slider button. Is it possible to create an element that will be called by more compact code?
Answer the question
In order to leave comments, you need to log in
To do this, you can create a UserControl or a CustomControl.
In the first case, you create a UserControl (user control) by adding it to the project as an application window. You set it up as a part of the application window by adding the necessary controls to it and describing the logic in the code. After compiling the project, the control automatically gets to 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 />
</Grid.RowDefinitions>
<TextBox />
<ListBox Grid.Row="1" />
</Grid>
</UserControl>
public MyTextBox : TextBox
{
}
<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>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question