public HostUserControl() { // UserControls InitializeComponent(); this.DockPanel1.DataContext = this; UserControls = Assembly.GetEntryAssembly().GetTypes() .Where(a => typeof(UserControl).IsAssignableFrom(a)) .Select(a => (UserControl)Activator.CreateInstance(a)) .GroupBy(a => string.IsNullOrEmpty(a.Name) ? a.GetType().Name.Replace("UserControl", string.Empty) : a.Name) .OrderBy(a => a.Key) .ToDictionary(); ItemsControl1.ItemsSource = UserControls; ContentControl1.Content = UserControls.FirstOrDefault().Value; }
public HostUserControl() { // UserControls InitializeComponent(); this.DockPanel1.DataContext = this; UserControls = Assembly .GetEntryAssembly() .GetTypes() .Where(a => typeof(UserControl).IsAssignableFrom(a)) .GroupBy(a => a.Name?.Replace("UserControl", string.Empty)) .OrderBy(a => a.Key) .ToDictionaryOnIndex() .ToDictionary(a => a.Key, a => new Func <UserControl>(() => (UserControl)Activator.CreateInstance(a.Value))); MainListBox.ItemsSource = UserControls; ContentControl1.Content = UserControls.FirstOrDefault().Value.Invoke(); MainListBox.SelectAddChanges().Subscribe(async => { ContentControl1.Content = ((KeyValuePair <string, Func <UserControl> >)MainListBox.SelectedItem).Value.Invoke(); }); }