WPF,请问这样的UserControl该怎么创建?
项目中,需要创建很多个继承自UserControl的用户控件,由于这些控件有些内容是相同的,所以,可不可以创建一个基类,然后让那些用户控件派生自这个基类呢?
我试了一下,首先在项目中创建一个继承自UserControl的基类BaseUserControl,然后让用户控件继承自这个BaseUserControl,如下:
<local:BaseUserControl x:Class="WPF1.UserControl1"
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"
xmlns:local="clr-namespace:WPF1"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
</Grid>
</local:BaseUserControl>
public partial class UserControl1 : BaseUserControl
{
public UserControl1()
{
InitializeComponent();
}
}