Add custom control to wpf window

I have a user control that I created, but when I go to add it to XAML in the window, intellisense does not pick it up, and I cannot figure out how to add it to the window.

I am pulling my hair here!

Any help is much appreciated!

+62
wpf user-controls
Jul 07 '09 at 16:39
source share
4 answers

You need to add the link inside the window tag. Something like:

xmlns:controls="clr-namespace:YourCustomNamespace.Controls;assembly=YourAssemblyName" 

(When you add xmlns: controls = "intellisense should hit to make this bit easier)

Then you can add the control with:

 <controls:CustomControlClassName ..... /> 
+72
Jul 07 '09 at 16:44
source share
— -

You probably need to add a namespace :

 <Window x:Class="UserControlTest.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:UserControlTest" Title="User Control Test" Height="300" Width="300"> <local:UserControl1 /> </Window> 
+15
Jul 07 '09 at 16:45
source share

some tips: first, make sure that xmlns is at the top, which includes the namespace that your control is in.

 xmlns:myControls="clr-namespace:YourCustomNamespace.Controls;assembly=YourAssemblyName" <myControls:thecontrol/> 

second, sometimes intellisense is stupid.

+12
Jul 07 '09 at 16:45
source share

Here's how I earned it:

WPF User Interface

 <UserControl x:Class="App.ProcessView" 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> </UserControl> 



C # user control

 namespace App { /// <summary> /// Interaction logic for ProcessView.xaml /// </summary> public partial class ProcessView : UserControl // My custom User Control { public ProcessView() { InitializeComponent(); } } } 



MainWindow WPF

 <Window x:Name="RootWindow" x:Class="App.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:app="clr-namespace:App" Title="Some Title" Height="350" Width="525" Closing="Window_Closing_1" Icon="bouncer.ico"> <Window.Resources> <app:DateConverter x:Key="dateConverter"/> </Window.Resources> <Grid> <ListView x:Name="listView" > <ListView.ItemTemplate> <DataTemplate> <app:ProcessView /> </DataTemplate> </ListView.ItemTemplate> </ListView> </Grid> </Window> 
+2
Feb 06 '17 at 11:45
source share



All Articles