I am using MVVM
pattern, my application is basically TabControl
with 3 TabItems
with DataGrids inside them.
I can save all data from grids to csv files and load it back. I try to add functionality that after user clicks button, a new window of string collection with all DataGrids
validation errors pops out. I almost succeeded but I find out that I have to click through all TabItems
to fire up their IDateErrorInfo
property validation and gather the strings.
So my question is how can I manually fire the validation of specific tab from code? I tried something like jump through all tabs with SelectedIndex
property of TabControl
in loop firing PropertyChanged("SelectedIndex")
each time and it changes the tab but doesn't fire validation and I get errors only from last, now visible tab.
EDIT
More details:
My every tab has its own ViewModel
with ObservableCollection<[TabModel]>
connected to DataGrid
. All 3 TabModels have implemented IDataErrorInfo
interface. Every tab has own xaml file and all these files are gathered in MainWindows.xaml's TabControl
like this:
<TabControl SelectedIndex="{Binding SelectedTab, UpdateSourceTrigger=PropertyChanged}">
<TabItem Width="auto" Header="FOO" Name="Foo">
<Controls:Foo DataContext="{Binding FooVM}"/>
</TabItem>
...
</TabControl>
In Foo.xaml I have simple DataGrid with columns and validation turned on on specific column, i.e.:
<DataGridTextColumn Header="ID" Binding="{Binding Id, ValidatesOnDataErrors=True}"/>
In every TabModel I have List<string> Errors
to which I add every result from IDataErrorInfo
public string this[string name]
I try to get/do all validation from MainWindowVM's code position.