コード例 #1
0
ファイル: ViewEngine.cs プロジェクト: sat1582/CODEFramework
        /// <summary>
        /// Tries the get the document.
        /// </summary>
        /// <param name="searchPath">The search path.</param>
        /// <returns>ViewEngineResult.</returns>
        protected virtual ViewEngineResult TryGetView(string searchPath)
        {
            try
            {
                var uri = searchPath.StartsWith("pack://") ? new Uri(searchPath) : new Uri(searchPath, UriKind.Relative);
                var view = Application.LoadComponent(uri) as FrameworkElement;
                if (view != null)
                {
                    var viewInfo = view as IViewInformation;
                    if (viewInfo != null)
                        viewInfo.OriginalViewLoadLocation = searchPath;

                    var viewResult = new ViewEngineResult
                    {
                        View = view,
                        FoundView = true,
                        ViewSource = "XAML Resource: " + searchPath
                    };

                    TryAttachingLayoutResources(view, searchPath);

                    return viewResult;
                }
            }
            catch
            {
            }
            return null;
        }
コード例 #2
0
ファイル: ViewEngine.cs プロジェクト: sat1582/CODEFramework
        /// <summary>Finds and instantiates the specified document</summary>
        /// <param name="viewName">Name of the document to find</param>
        /// <param name="controllerName">Name of the controller that requested the document</param>
        /// <returns>Document result indicating the success of the operation</returns>
        public ViewEngineResult GetView(string viewName, string controllerName)
        {
            if (!viewName.StartsWith("CODEFrameworkStandardView")) return new ViewEngineResult {FoundView = false};
            if (viewName.StartsWith("CODEFrameworkStandardViewNone")) return new ViewEngineResult {FoundView = false};

            viewName = viewName.Replace("CODEFrameworkStandardView", string.Empty);

            var result = new ViewEngineResult();

            var view = new StandardViewGrid {ViewName = viewName};
            view.Children.Add(GetViewInternal(viewName));

            result.FoundView = true;
            result.View = view;
            result.ViewSource = "Standard Document: " + viewName;

            return result;
        }
コード例 #3
0
ファイル: ViewEngine.cs プロジェクト: sat1582/CODEFramework
        /// <summary>
        /// Finds and instantiates the specified document
        /// </summary>
        /// <param name="viewName">Name of the document to find</param>
        /// <param name="controllerName">Name of the controller that requested the document</param>
        /// <returns>
        /// Document result indicating the success of the operation
        /// </returns>
        public ViewEngineResult GetView(string viewName, string controllerName)
        {
            viewName = viewName.ToLower();

            var failureResult = new ViewEngineResult { FoundView = false };

            var searchPath = "/views/" + controllerName + "/" + viewName + ".xaml";
            var viewResult = TryGetView(searchPath);
            if (viewResult != null) return viewResult;
            failureResult.LocationsSearched.Add(searchPath);

            searchPath = "/views/shared/" + viewName + ".xaml";
            viewResult = TryGetView(searchPath);
            if (viewResult != null) return viewResult;
            failureResult.LocationsSearched.Add(searchPath);

            foreach (var assemblyName in ApplicationEx.SecondaryAssemblies.Keys)
            {
                var secondaryAssembly = ApplicationEx.SecondaryAssemblies[assemblyName];

                searchPath = "/" + secondaryAssembly.GetName().Name + ";component/views/" + controllerName + "/" + viewName + ".xaml";
                viewResult = TryGetView(searchPath);
                if (viewResult != null) return viewResult;
                failureResult.LocationsSearched.Add(searchPath);

                searchPath = "/" + secondaryAssembly.GetName().Name + ";component/views/shared/" + viewName + ".xaml";
                viewResult = TryGetView(searchPath);
                if (viewResult != null) return viewResult;
                failureResult.LocationsSearched.Add(searchPath);
            }

            return failureResult;
        }