I have a main view in which I have a tab control. The content of each tab is a treeview which is present in different views. This is my main view in which I use 2 other views
In my FirstListView, I have a tree view, a textbox and a button.
<TabControl x:Name ="MainTab" SelectionChanged="OnTabSelectionChanged">
<TabItem Header="First" >
<view:FirstListView x:Name="FirstView"/>
</TabItem>
<TabItem Header="Second" >
<view:SecondListView x:Name ="SecondView"/>
</TabItem>
</TabControl>
Textbox and the button are added to perform a search in the tree.
The view model associated with the FirstListView has a command that is initialized in its contructor.
_searchCommand = new SearchFamilyTreeCommand(this);
SearchFamiltyTreeCommand is a class that is derived from ICommand and the execute method calls a function to perform the search. This is present in the FirstViewModel.
#region SearchCommand
public ICommand SearchCommand
{
get { return _searchCommand; }
}
private class SearchFamilyTreeCommand : ICommand
{
readonly FunctionListViewModel _functionTree;
public SearchFamilyTreeCommand(FunctionListViewModel functionTree)
{
_functionTree = functionTree;
}
public bool CanExecute(object parameter)
{
return true;
}
event EventHandler ICommand.CanExecuteChanged
{
add { }
remove { }
}
public void Execute(object parameter)
{
_functionTree.PerformSearch();
}
}
#endregion
The search method is not type independent. It depends on the type present in its particular model. And the data required to perform the search is present in this view model.
This is working. Now I have to extend this functionality to other views ( SecondListView, ThirdListView and so on) which have their own treeviews(the type of the content is different from the FirstTreeView). How can I do it? Where shall I place the code and the command?