예제 #1
0
        private async Task ReloadFile(FileReload fileReload)
        {
            Windows.ApplicationModel.Core.CoreApplication.MainView.Dispatcher.RunAsync(
                Windows.UI.Core.CoreDispatcherPriority.Normal,
                async() =>
            {
                try
                {
                    if (this.Log().IsEnabled(LogLevel.Debug))
                    {
                        this.Log().LogDebug($"Reloading changed file [{fileReload.FilePath}]");
                    }

                    var uri = new Uri("file:///" + fileReload.FilePath.Replace("\\", "/"));

                    Application.RegisterComponent(uri, fileReload.Content);

                    foreach (var instance in EnumerateInstances(Window.Current.Content, uri))
                    {
                        switch (instance)
                        {
#if __IOS__
                        case UserControl userControl:
                            SwapViews(userControl, XamlReader.LoadUsingXClass(fileReload.Content) as UIKit.UIView);
                            break;
#endif
                        case ContentControl content:
                            SwapViews(content, XamlReader.LoadUsingXClass(fileReload.Content) as ContentControl);
                            break;
                        }
                    }

                    if (ResourceResolver.RetrieveDictionaryForFilePath(uri.AbsolutePath) is { } targetDictionary)
                    {
                        var replacementDictionary = (ResourceDictionary)XamlReader.Load(fileReload.Content);
                        targetDictionary.CopyFrom(replacementDictionary);
                        Application.Current.UpdateResourceBindingsForHotReload();
                    }
                }
                catch (Exception e)
                {
                    if (this.Log().IsEnabled(LogLevel.Error))
                    {
                        this.Log().LogError($"Failed reloading changed file [{fileReload.FilePath}]", e);
                    }

                    await _rcClient.SendMessage(
                        new HotReload.Messages.XamlLoadError(
                            filePath: fileReload.FilePath,
                            exceptionType: e.GetType().ToString(),
                            message: e.Message,
                            stackTrace: e.StackTrace));
                }
            });
예제 #2
0
        private async Task ReloadFile(FileReload fileReload)
        {
            Windows.UI.Core.CoreDispatcher.Main.RunAsync(
                Windows.UI.Core.CoreDispatcherPriority.Normal,
                async() =>
            {
                try
                {
                    if (this.Log().IsEnabled(LogLevel.Debug))
                    {
                        this.Log().LogDebug($"Reloading changed file [{fileReload.FilePath}]");
                    }

                    var uri = new Uri("file:///" + fileReload.FilePath.Replace("\\", "/"));

                    foreach (var instance in EnumerateInstances(Window.Current.Content, uri))
                    {
                        switch (instance)
                        {
#if __IOS__
                        case UserControl userControl:
                            userControl.Content = XamlReader.Load(fileReload.Content) as UIKit.UIView;
                            break;
#endif
                        case ContentControl content:
                            content.Content = XamlReader.Load(fileReload.Content);
                            break;
                        }
                    }
                }
                catch (Exception e)
                {
                    if (this.Log().IsEnabled(LogLevel.Error))
                    {
                        this.Log().LogError($"Failed reloading changed file [{fileReload.FilePath}]", e);
                    }

                    await _rcClient.SendMessage(
                        new HotReload.Messages.XamlLoadError(
                            filePath: fileReload.FilePath,
                            exceptionType: e.GetType().ToString(),
                            message: e.Message,
                            stackTrace: e.StackTrace));
                }
            });