Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WPF中的继承_C#_Wpf_Inheritance - Fatal编程技术网

C# WPF中的继承

C# WPF中的继承,c#,wpf,inheritance,C#,Wpf,Inheritance,我希望像这样继承WPF控件 public class BaseView : UserControl { ... } public class BaseListView : BaseView { ... } public class TeachersListView: BaseListView { } public class StudentsListView : BaseListView { } 这里的“BaseListView”是基本类。这些类可能有几个功能,这

我希望像这样继承WPF控件

public class BaseView : UserControl
{
   ...  
}    

public class BaseListView : BaseView
{
   ...
}

public class TeachersListView: BaseListView
{
}

public class StudentsListView : BaseListView
{
}
这里的“BaseListView”是基本类。这些类可能有几个功能,这取决于“BaseListView”中的ListView。我想将这个“BaseListView”继承到多个视图中,这些视图可以添加多个列,并具有不同的数据绑定。所以我的要求是

class BaseListView : BaseView
{
  This class will have the UI parts like commandStrip and followed by "Empty ListView".

  This "ListView" may not hold any columns in it.
}    

class StudentsListView:  BaseListView
{    
   In **XAML** part, Columns and its appropriate Data Binding will be added. I need to access the controls in .cs file. so that i can access the controls.

  void FindAndHighlightColumn()
   {
     // get the columns to find and search the list view and highlight.
   }
}

如何实现这一点,正确的方法是什么。

您使用的是模型视图模型体系结构吗?读了你的问题后,我最初的想法是,我不会像你所想的那样使用继承。相反,我会考虑作文。
例如,能否通过组合多个用户控件的.xaml文件来创建复合StudentsListView?可以使用一个用户控件来显示commandStrip,也可以使用另一个用户控件来显示相应的ListView(例如StudentListViewUserControl、TeacherListViewUserControl等)

您是否使用模型视图模型体系结构?读了你的问题后,我最初的想法是,我不会像你所想的那样使用继承。相反,我会考虑作文。
例如,能否通过组合多个用户控件的.xaml文件来创建复合StudentsListView?可以使用一个用户控件来显示commandStrip,也可以使用另一个用户控件来显示相应的ListView(例如StudentListViewUserControl、TeacherListViewUserControl等)

我认为您需要创建一个UserControl(Items或ContentControl),其中包含一些基本功能,如FindAndHighlightColumn()


您可以创建BaseListView“lookless”,然后使用ControlTemplates获得多种样式(创建样式,如“StudentListViewStyle”等,每个样式都有一个合适的ControlTemplate)。ControlTemplate是一个视图,因此您可以在每个模板中指定不同的绑定,要按控件名称访问控件,您需要定义一个与某些名为“PART_XY”等部分的约定,以标准ProgressBar控件为例。

我想您需要创建一个UserControl(Items-或ContentControl)具有一些基本功能,如FindAndHighlightColumn()

您可以创建BaseListView“lookless”,然后使用ControlTemplates获得多种样式(创建样式,如“StudentListViewStyle”等,每个样式都有一个合适的ControlTemplate)。ControlTemplate是一个视图,因此您可以在每个模板中指定不同的绑定,要按控件名称访问控件,您需要使用名为“PART_XY”等的特定部分定义约定,以标准ProgressBar控件为例。

我们现在使用的是“composition”,但很难概括。比如说,在CommandStrip中,我可以删除、关闭事件。如果我把这张照片放在“BassClass”中,我将有一个“ScreenInfo”类,它将保存所有可以提供给执行事件的信息。如果我有“继承权”,我可以将“ScreenInfo”传递给base,供所有人使用。如果这是作文,我必须通过所有的“作文”作品。我们现在面临的问题,这就是我寻求继承的原因。我们在某些地方使用模型视图模型、MVP和MVC。我们现在使用的是“合成”,但很难一概而论。比如说,在CommandStrip中,我可以删除、关闭事件。如果我把这张照片放在“BassClass”中,我将有一个“ScreenInfo”类,它将保存所有可以提供给执行事件的信息。如果我有“继承权”,我可以将“ScreenInfo”传递给base,供所有人使用。如果这是作文,我必须通过所有的“作文”作品。我们现在面临的问题,这就是我寻求继承的原因。我们在某些地方使用模型视图模型、MVP和MVC。在未来,它将是一个。