Beispiel #1
0
        /// <summary>
        /// Method executes when the SelectionChanged command is invoked.
        /// The parameter <paramref name="p"/> can be an array of objects
        /// containing objects of the <seealso cref="IFolderItemViewModel"/> type
        /// or p can also be string.
        ///
        /// Each parameter item that adheres to the above types results in
        /// a OnCurrentPathChanged event being fired with the folder path
        /// as parameter.
        ///
        /// This mwthod can typically be invoked by:
        /// 1> Edit the text portion + Enter in the control or
        /// 2> By selecting an entry from the drop down list of the combobox.
        /// </summary>
        /// <param name="p"></param>
        private async Task SelectionChanged_ExecutedAsync(object p)
        {
            if (p == null)
            {
                return;
            }

            // Check if the given parameter is a string, fire a corresponding event if so...
            if (p is string)
            {
                IPathModel param = null;
                try
                {
                    param = PathFactory.Create(p as string);
                }
                catch
                {
                    return;   // Control will refuse to select an unknown/non-existing item
                }

                // This breaks a possible recursion, if a new view is requested even though its
                // already available, because this could, otherwise, change the SelectedItem
                // which in turn could request another PopulateView(...) -> SelectedItem etc ...
                if (SelectedItem != null)
                {
                    if (SelectedItem.Equals(param))
                    {
                        return;
                    }
                }

                if (param != null)
                {
                    var request = new BrowseRequest(param);
                    await InternalPopulateViewAsync(request, true);
                }
            }
            else
            {
                if (p is object[])
                {
                    var param = p as object[];

                    if (param != null)
                    {
                        if (param.Length > 0)
                        {
                            var newPath = param[param.Length - 1] as IFolderItemViewModel;

                            if (newPath != null)
                            {
                                IPathModel location          = null;
                                IPathModel selectedItemModel = null;
                                try
                                {
                                    location          = PathFactory.Create(newPath.ItemPath, newPath.ItemType);
                                    selectedItemModel = PathFactory.Create(SelectedItem.ItemPath, SelectedItem.ItemType);
                                }
                                catch
                                {
                                }

                                if (location == null || selectedItemModel == null)
                                {
                                    return;
                                }

                                // This breaks a possible recursion, if a new view is requested even though its
                                // already available, because this could, otherwise, change the SelectedItem
                                // which in turn could request another PopulateView(...) -> SelectedItem etc ...
                                if (location.Equals(selectedItemModel))
                                {
                                    return;
                                }

                                var request = new BrowseRequest(location);
                                await InternalPopulateViewAsync(request, true);
                            }
                        }
                    }
                }
            }
        }