Leonard Lee

Hi all,

How can I reuse the custom user control that I have created in .NET 2.0 framework in the UserControl class on to WPF XAML

Thanks in advance.


Re: Windows Presentation Foundation (WPF) Reuse Custom User Control on .NET 2.0 on WPF XAML

Rakesh Ravuri

Lee,

 

Use WindowsFormsHost Control to acheive this

<Window x:Class="Window1"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" 
  Title="HostingWfInWpf"
  >

 <Grid>

  <WindowsFormsHost>
   <wf:MaskedTextBox x:Name="mtbDate" Mask="00/00/0000"/>
  </WindowsFormsHost>

 </Grid>


</Window>
cheers!
Rakesh Ravuri




Re: Windows Presentation Foundation (WPF) Reuse Custom User Control on .NET 2.0 on WPF XAML

Leonard Lee

Thanks, Ravuri,

But the control is the MaskedTextBox which is default .NET 2.0 control. BUt, how about the custom control that I have created e.g. A UserControl that I custom made with a textbox and dateTimePicker, let call it, the class inherited from UserControl named DatePreviewTextBox.

So, the same codes does apply

Thanks!




Re: Windows Presentation Foundation (WPF) Reuse Custom User Control on .NET 2.0 on WPF XAML

Yi-Lun Luo - MSFT

You can use the similar codes. Just change the MaskedTextBox to your own control. Don't forget to include the correct namespace.




Re: Windows Presentation Foundation (WPF) Reuse Custom User Control on .NET 2.0 on WPF XAML

Leonard Lee

Thanks, Luo.

But I faced this warning messages in my application whereby I implemented the codes given by Ravuri (the codes was available in MSDN Library also).

How to I clear or solve the warnings

Thanks!

------------------------------

Warning 1 The element 'StackPanel' in namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation' has invalid child element 'WindowsFormsHost' in namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation'. List of possible elements expected: 'StackPanel.CanHorizontallyScroll, StackPanel.CanVerticallyScroll, StackPanel.ScrollOwner, StackPanel.Background, StackPanel.IsItemsHost, StackPanel.Style, StackPanel.OverridesDefaultStyle, StackPanel.Triggers, StackPanel.Resources, StackPanel.DataContext, StackPanel.Language, StackPanel.Tag, StackPanel.InputScope, StackPanel.LayoutTransform, StackPanel.Width, StackPanel.MinWidth, StackPanel.MaxWidth, StackPanel.Height, StackPanel.MinHeight, StackPanel.MaxHeight, StackPanel.Margin, StackPanel.FocusVisualStyle, StackPanel.Cursor, StackPanel.ForceCursor, StackPanel.ToolTip, StackPanel.ContextMenu, StackPanel.InputBindings, StackPanel.CommandBindings, StackPanel.AllowDrop, StackPanel.RenderSize, StackPanel.RenderTransform, StackPanel.RenderTransformOrigin, StackPanel.Opacity, StackPanel.OpacityMask, StackPanel.BitmapEffect, StackPanel.BitmapEffectInput, StackPanel.ClipToBounds, StackPanel.Clip, StackPanel.SnapsToDevicePixels, StackPanel.IsEnabled, StackPanel.IsHitTestVisible, StackPanel.Focusable, sgUIElement....

------------------------------





Re: Windows Presentation Foundation (WPF) Reuse Custom User Control on .NET 2.0 on WPF XAML

Yi-Lun Luo - MSFT

I think you can ignore this warning. The wpf xml schema doesn't include your own controls's definition. It disobeys xml schema, but it won't cause any problems when running the application.