SciFiMage

I have through many resources on the web about this but I can only find out about how to host a wpf user control within a standard windows forms application. Does anyone know the basic code to be able to host a wpf user control within a wpf windows application Any help would be greatly appreciated.

Best regards

For example, code for user control. I just want to be able to display it on a wpf form.

<UserControl x:Class="CAMAlpha.uc"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="145" Width="242">
<Grid>
<Button Height="23" Margin="66,38,101,0" Name="button1" VerticalAlignment="Top" >Button</Button>
<PasswordBox Height="26" Margin="66,0,76,32" Name="passwordBox1" VerticalAlignment="Bottom" />
</Grid>
</UserControl>


Again i just want to be able to display this control on a wpf form.



Re: Windows Presentation Foundation (WPF) How do i host a wpf user control within a wpf windows application.

Carole Snyder

<Window x:Class="CustomPopupTextBox.Window1"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns: src="clr-namespace:CAMAlpha"*

>

<src:uc/>

</Window>

If the User control is in a different assembly than the app, use xmlns: src="clr-namespace:CAMAlpha;assembly=NameOfAssembly"

*The space is to avoid emoticons. xmlsn: src should not have a space.






Re: Windows Presentation Foundation (WPF) How do i host a wpf user control within a wpf windows application.

SciFiMage

thanks but it does not work. Any other ideas I kept getting namespace errors saying it cant find the namespace(tried that being that the control was in the same project). Also i was wondering if i can declare and display the user control using c# code instead of the xaml because i have load these controls dynamically. thanks




Re: Windows Presentation Foundation (WPF) How do i host a wpf user control within a wpf windows application.

Yi-Lun Luo - MSFT

Hello, are you using Visual Studio 2005 with WPF extension If so, when you try to add a UserControl in XAML, youre likely to get some error messages. But if you run the program, all will be OK. This is the problems in designer, not in WPF itself. Visual Studio Orcas has fixed this problem. You can just ignore it as long as you can run your application. If you want to add the UserControl in code, you can use something like:

this.Content = new uc();

grid1.Children.Add(new uc());