Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF tutorial for creating a custom usercontrol

I'm looking for a tutorial that explains creating custom usercontrols in WPF.

I want to have one control that combines a textblock, a textbox, and a button that launches a common fileopen dialog. I have the layout done and everything wired up. It's works but it's three independent controls. Hopefully there is a tutorial out there that explains how to turn this into one usercontrol and wire up everything so I can expose certain properties of the control, like the text in the textbox, to the rest of my WPF app.

like image 554
DenaliHardtail Avatar asked Jul 02 '09 20:07

DenaliHardtail


People also ask

What is a WPF UserControl?

User controls, in WPF represented by the UserControl class, is the concept of grouping markup and code into a reusable container, so that the same interface, with the same functionality, can be used in several different places and even across several applications.

How do I customize WPF controls?

Create a new WPF project and then right-click on your solution and select Add > New Item... It will open the following window. Now select Custom Control (WPF) and name it MyCustomControl. Click the Add button and you will see that two new files (Themes/Generic.

How do you call a user control in WPF?

<Grid. ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>

How do I add user control to XAML?

The XamlFileBrowser Control Create a XAML application using Visual Studio 2008 and add a new item by right clicking on the project, select Add >> New Item from the menu and select User Control from the available templates.


1 Answers

This looks like a good article that might help.

http://www.c-sharpcorner.com/uploadfile/mahesh/user-control-in-wpf/

In fact, it looks like he's doing exactly what you're trying to do. As for accessing the TextBox contents from outside the user control, create a public property as shown in the article.

public string FileName
{
    get { return FBCTextBox.Text; }
    set { FBCTextBox.Text = value; }
}
like image 178
CoderDennis Avatar answered Sep 28 '22 05:09

CoderDennis