简体   繁体   English

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

[英]Create custom user controls in wpf for reuse

I was wondering how could I save a user control just like we can save ac# class in a dll file and import that file whenever we need to use that class. 我想知道如何保存用户控件就像我们可以在一个dll文件中保存ac#类并在我们需要使用该类时导入该文件一样。 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. 如果我们可以制作自定义控件并将它们保存以供重用,而不是每次我们必须使用它时都必须复制xaml和代码,这将是很好的。

You have exactly that flexibility with WPF and a lot of choices. 你对WPF有很多灵活性和很多选择。 Here is an excellent introduction to your options: 以下是对您的选择的精彩介绍:

These choices include: 这些选择包括:

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

The tradeoffs are described in detail in the article. 在文章中详细描述了权衡。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM