Reputation: 1781
I want to have the WPF controls inherited like this,
public class BaseView : UserControl
{
...
}
public class BaseListView : BaseView
{
...
}
public class TeachersListView: BaseListView
{
}
public class StudentsListView : BaseListView
{
}
Here "BaseListView" is the base classed. This classes may have several functionalities which depends on the ListView present in "BaseListView". I want to inherit this "BaseListView" to several views which may add several column's and with different databindings. So my requirement is
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.
}
}
How can i achieve this, what is the right way to do this.
Upvotes: 1
Views: 774
Reputation: 4481
I think you want to create a UserControl (Items- or ContentControl) with some basic functionality like FindAndHighlightColumn().
You can create your BaseListView "lookless" and then use ControlTemplates to get several flavours of it (create styles like "StudentListViewStyle" etc., each with an appropriate ControlTemplate). A ControlTemplate is a view, so you can specify different bindings in each template, to access controls by their names you need to define a convention with certain parts named 'PART_XY' etc., look at the standard ProgressBar-Control for an example.
Upvotes: 1
Reputation: 15133
Are you using Model-View-ViewModel architecture? After reading your question, my initial thought is that I would not use inheritance to the extent you are thinking of. Instead, I would consider composition.
For example, could you create a composite StudentsListView by composing a .xaml file of multiple user controls? Maybe a user control to display your commandStrip and another user control to display the appropriate ListView (e.g. StudentListViewUserControl, TeacherListViewUserControl, etc.).
Upvotes: 0