在wpf中创建自定义用户控件以供重用

时间:2022-09-28 16:03:17

I was wondering how could I save a user control just like we can save a c# class in a dll file and import that file whenever we need to use that class. How could we import that control and use it. It will be nice if we could make custom controls and save them for reuse instead of having to copy the xaml and code behind every time we had to use it.

我想知道如何保存用户控件就像我们可以在dll文件中保存c#类并在需要使用该类时导入该文件一样。我们怎样才能导入该控件并使用它。如果我们可以制作自定义控件并将它们保存以供重用,而不是每次我们必须使用它时都必须复制xaml和代码,这将是很好的。

1 个解决方案

#1


7  

You have exactly that flexibility with WPF and a lot of choices. Here is an excellent introduction to your options:

你对WPF有很多灵活性和很多选择。以下是对您的选择的精彩介绍:

These choices include:

这些选择包括:

  • Deriving from UserControl
  • 从UserControl派生

  • Deriving from Control
  • 从控制中衍生出来

  • Deriving from FrameworkElement
  • 从FrameworkElement派生

The tradeoffs are described in detail in the article.

在文章中详细描述了权衡。

#1


7  

You have exactly that flexibility with WPF and a lot of choices. Here is an excellent introduction to your options:

你对WPF有很多灵活性和很多选择。以下是对您的选择的精彩介绍:

These choices include:

这些选择包括:

  • Deriving from UserControl
  • 从UserControl派生

  • Deriving from Control
  • 从控制中衍生出来

  • Deriving from FrameworkElement
  • 从FrameworkElement派生

The tradeoffs are described in detail in the article.

在文章中详细描述了权衡。