Beispiel #1
0
        /// <summary>
        /// 导航至某视图
        /// </summary>
        /// <param name="navigationKey">导航键值</param>
        /// <param name="load"></param>
        public void NavigationTo(string navigationKey)
        {
            XlyNavigationConfig config = this.GetNavigationConfig(navigationKey);

            if (config == null || config.ViewType == null && config.FunCreateView == null)
            {
                return;
            }
            if (this.PART_Root == null)
            {
                this.ApplyTemplate();
            }

            this.BuildConfig(config, null, null);

            foreach (var kv in this._Pool)
            {
                if (kv.Key == config)
                {
                    kv.Value.Visibility = System.Windows.Visibility.Visible;
                }
                else
                {
                    kv.Value.Visibility = System.Windows.Visibility.Collapsed;
                }
            }
            this.CurrentConfig = config;
        }
Beispiel #2
0
        /// <summary>
        /// 列表选项改变时触发
        /// </summary>
        private void PART_ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (this.PART_Navigation == null)
            {
                this.ApplyTemplate();
            }
            if (this.PART_Navigation == null)
            {
                return;
            }

            XlyMultiViewInfo info = this.PART_ListBox.SelectedValue as XlyMultiViewInfo;

            if (info == null)
            {
                return;
            }
            XlyNavigationConfig lastConfig = this.PART_Navigation.CurrentConfig;

            if (string.IsNullOrWhiteSpace(info.NavigationKey))
            {
                info.NavigationKey = Guid.NewGuid().ToString();
                Type viewType = info.ViewType;
                if (viewType == null)
                {
                    viewType = typeof(XlyMultiNoneView);
                }
                XlyNavigationConfig config_temp = new XlyNavigationConfig();
                config_temp.ViewType      = viewType;
                config_temp.NavigationKey = info.NavigationKey;
                this.PART_Navigation.NavigationConfigs.Add(config_temp);
            }
            XlyNavigationConfig config = this.PART_Navigation.GetNavigationConfig(info.NavigationKey);

            this.PART_Navigation.NavigationTo(info.NavigationKey);
            if (config.View is IXlyMultiView)
            {
                IXlyMultiView imv = config.View as IXlyMultiView;
                imv.MultiViewOwner   = this;
                imv.LinkedControl    = this.LinkedControl;
                imv.Doamin           = this.Doamin;
                imv.ItemsSourceOwner = this.ItemsSourceOwner;
                imv.ColumnsSource    = this.ColumnsSource;
                imv.ViewsSource      = this.ViewsSource;
                imv.CurrentViewInfo  = info;
                if (imv.IsSupport(null))
                {
                    imv.ItemsSource = this.ItemsSource;
                }
                imv.OnActivation();
                if (lastConfig != null && lastConfig.View is IXlyMultiView)
                {
                    ((IXlyMultiView)lastConfig.View).OnDeactivation();
                }
            }
        }
Beispiel #3
0
        private void View_Loaded(object sender, RoutedEventArgs e)
        {
            FrameworkElement    fe     = sender as FrameworkElement;
            XlyNavigationConfig config = this.GetNavigationConfig(fe);

            if (config != null && config.OnLoad != null)
            {
                Action <FrameworkElement> action = config.OnLoad;
                config.OnLoad       = null;
                config.View.Loaded -= this.View_Loaded;
                action(fe);
            }
        }
Beispiel #4
0
        /// <summary>
        /// 移除视图
        /// </summary>
        /// <param name="navigationKey">导航键值</param>
        public void RemoveConfig(string navigationKey)
        {
            XlyNavigationConfig config = this.GetNavigationConfig(navigationKey);

            if (config == null)
            {
                return;
            }

            if (this._Pool.ContainsKey(config))
            {
                this._Pool.Remove(config);
                this.PART_Root.Children.Remove(config.View);
            }
        }
Beispiel #5
0
        /// <summary>
        /// 构建控件导航配置
        /// </summary>
        /// <param name="navigationKey">导航键值</param>
        public void BuildConfig(string navigationKey, Action <FrameworkElement> actionCreateView, Action <object> actionCreateViewModel)
        {
            XlyNavigationConfig config = this.GetNavigationConfig(navigationKey);

            this.BuildConfig(config, actionCreateView, actionCreateViewModel);
        }
Beispiel #6
0
        /// <summary>
        /// 构建导航配置
        /// </summary>
        /// <param name="config"></param>
        public void BuildConfig(XlyNavigationConfig config, Action <FrameworkElement> actionCreateView, Action <object> actionCreateViewModel)
        {
            if (config == null || config.ViewType == null && config.FunCreateView == null)
            {
                return;
            }
            if (this.PART_Root == null)
            {
                this.ApplyTemplate();
            }

            if (!this._Pool.ContainsKey(config))
            {
                if (config.View == null)
                {
                    if (config.FunCreateView != null)
                    {
                        config.View = config.FunCreateView(config);
                    }
                    else
                    {
                        config.View = config.ViewType.Assembly.CreateInstance(config.ViewType.FullName) as FrameworkElement;
                    }
                    if (actionCreateView != null)
                    {
                        actionCreateView(config.View);
                    }
                }
                if (config.ViewModelType != null || config.ViewModel != null || config.FunCreateViewModel != null)
                {
                    if (config.ViewModel == null)
                    {
                        if (config.FunCreateViewModel != null)
                        {
                            config.ViewModel = config.FunCreateViewModel(config);
                        }
                        else
                        {
                            config.ViewModel = config.ViewModelType.Assembly.CreateInstance(config.ViewModelType.FullName);
                        }
                        if (actionCreateViewModel != null)
                        {
                            actionCreateViewModel(config.ViewModel);
                        }
                    }
                    if (config.ViewModel is XlyNavigationViewModelBase)
                    {
                        XlyNavigationViewModelBase vm = config.ViewModel as XlyNavigationViewModelBase;
                        vm.Config     = config;
                        vm.Navigation = this;
                    }
                    config.View.DataContext = config.ViewModel;
                }
                this._Pool.Add(config, config.View);
                this.PART_Root.Children.Add(config.View);
                if (this.OnBuildConfig != null)
                {
                    this.OnBuildConfig(this, new XlyNavigationEventArgs {
                        Config = config
                    });
                }
            }
        }