简体   繁体   中英

Multiple instances of UserControl in WPF MVVM application

I have a requirement ie one view should have multiple instances at runtime for loading data of different employees from an Xml file eg employee form for creating a new employee details and loading from xml file. I did some search on google and found a very useful link http://msdn.microsoft.com/en-us/magazine/dd419663.aspx

For a WPF MVVM application, it is perfect when multiple instances of the ViewModel are created the view reciprocates. The only problem I see is when I place the text box control with TabControl TabItem ie when I select a particular tab item with in Tab control the other instances of the view reciprocate the same way. How do I prevent the application from doing this? Is there a property of TabItem which could be bound?

If any one has similar issue the solution is to bind SelectedTabGridIndex to RadTabItem .

private int _selectedTabGridIndex;
public int SelectedTabGridIndex
{
    get { return _selectedTabGridIndex; }
    set
    {
        if (value == _selectedTabGridIndex)
            return;

        _selectedTabGridIndex = value;
        base.OnPropertyChanged("SelectedTabGridIndex");
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM