private void AddThemeResource(List <Mubox.View.Themes.ThemeDescriptor> themesList, string themeName) { try { var uri = new Uri("pack://siteoforigin:,,,/View/Themes/" + themeName + ".xaml", UriKind.Absolute); var resourceInfo = Application.GetRemoteStream(uri); var reader = new System.Windows.Markup.XamlReader(); ResourceDictionary resourceDictionary = (ResourceDictionary)reader.LoadAsync(resourceInfo.Stream); Mubox.View.Themes.ThemeDescriptor theme = new Mubox.View.Themes.ThemeDescriptor { Name = themeName, Resources = resourceDictionary }; themesList.Add(theme); if (Mubox.Configuration.MuboxConfigSection.Default.PreferredTheme == themeName) { Application.Current.Resources.MergedDictionaries.Add(theme.Resources); comboThemeSelector.SelectedItem = theme; } } catch (Exception ex) { Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); } }
private void SetThemeSource(Uri source, bool useThemeAccentColor) { if (source == null) { throw new ArgumentNullException("source"); } ResourceDictionary themeDict; if (source.IsAbsoluteUri && source.Scheme.StartsWith("pack")) { System.Windows.Resources.StreamResourceInfo info = Application.GetRemoteStream(source); System.Windows.Markup.XamlReader reader = new System.Windows.Markup.XamlReader(); themeDict = (ResourceDictionary)reader.LoadAsync(info.Stream); } else { themeDict = new ResourceDictionary { Source = source } }; AddTheme(themeDict, useThemeAccentColor); OnPropertyChanged("ThemeSource"); }
void Method4() { //<SnippetLoadAPageSOOFileManuallyCODE> // Navigate to xaml page Uri uri = new Uri("/SiteOfOriginFile.xaml", UriKind.Relative); StreamResourceInfo info = Application.GetRemoteStream(uri); System.Windows.Markup.XamlReader reader = new System.Windows.Markup.XamlReader(); Page page = (Page)reader.LoadAsync(info.Stream); this.pageFrame.Content = page; //</SnippetLoadAPageSOOFileManuallyCODE> }
public static T Get <T>(string resourceName) { var assembly = Assembly.GetExecutingAssembly(); using (var stream = assembly.GetManifestResourceStream("BusyBox.ResourceDictionary.xaml")) { var reader = new System.Windows.Markup.XamlReader(); var resDictionary = (ResourceDictionary)reader.LoadAsync(stream); return((T)resDictionary[resourceName]); } }
//function retranslator resource from uri public int add_res_dict(Uri _uri) { using (MemoryStream _tmpStream = new MemoryStream(Encoding.UTF8.GetBytes(_uri.ToString()))) { System.Windows.Markup.XamlReader xaml_reader = new System.Windows.Markup.XamlReader(); try { Dict_Res.MergedDictionaries.Add((ResourceDictionary)xaml_reader.LoadAsync(_tmpStream)); } catch (Exception ex) { return(0); } this.Resources = Dict_Res; } return(1); }
private void about_click(object sender, RoutedEventArgs e) { if (About == null) { var tab = uni_tab_creator("About", true); var grid = new WrapPanel(); About = new ContentControl(); Uri uri = new Uri(RCResourceLibs.vsresources.about, UriKind.Relative); //get content of connector from uri ResourceDictionary dict_res = new ResourceDictionary(); using (MemoryStream tmp_stream = new MemoryStream(Encoding.UTF8.GetBytes(uri.ToString()))) //translate stream to xaml markup { System.Windows.Markup.XamlReader xaml_reader = new System.Windows.Markup.XamlReader(); try { dict_res.MergedDictionaries.Add((ResourceDictionary)xaml_reader.LoadAsync(tmp_stream)); } catch (Exception ex) { } About.Resources = dict_res; } tab.Unloaded += delegate { About = null; }; About.Loaded += delegate { Hyperlink link = (Hyperlink)About.Template.FindName("Link", About); link.RequestNavigate += delegate(object _sender, System.Windows.Navigation.RequestNavigateEventArgs _e) { System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(_e.Uri.AbsoluteUri)); e.Handled = true; }; }; About.SetValue(Panel.ZIndexProperty, 110); grid.Children.Add(About); tab.Content = grid; } else { foreach (TabItem it in MainTab.Items) { if (it.Header == "About") { MainTab.SelectedItem = it; } } } }
private ResourceDictionary AddResources(FileInfo xamlFileInfo) { ResourceDictionary myResourceDictionary = null; try { Stream stream = File.OpenRead(xamlFileInfo.FullName); System.Windows.Markup.XamlReader reader = new System.Windows.Markup.XamlReader(); myResourceDictionary = (ResourceDictionary)reader.LoadAsync(stream); //Application.Current.Resources.MergedDictionaries.Add(myResourceDictionary); } catch (Exception e) { MessageBox.Show(string.Format(Properties.Resources.ErrorImportMessage, xamlFileInfo.FullName, $"{e.Source} - {e.Message}"), Properties.Resources.ErrorImport, MessageBoxButton.OK, MessageBoxImage.Error); } return(myResourceDictionary); }
public static void show_connector(Panel target_panel) //show connector into target_panel { Target_Panel = target_panel; VisualEffectsAndComponents.MainWindowVisualEffects.Curtain.curtain_fx( Target_Panel, System.Windows.Media.Brushes.White ); Cntr = new ContentControl(); Uri uri = new Uri(RCResourceLibs.vsresources.connector, UriKind.Relative); //get content of connector from uri ResourceDictionary dict_res = new ResourceDictionary(); using (MemoryStream tmp_stream = new MemoryStream(Encoding.UTF8.GetBytes(uri.ToString()))) //translate stream to xaml markup { System.Windows.Markup.XamlReader xaml_reader = new System.Windows.Markup.XamlReader(); try { dict_res.MergedDictionaries.Add((ResourceDictionary)xaml_reader.LoadAsync(tmp_stream)); } catch (Exception ex) { } Cntr.Resources = dict_res; } Cntr.SetValue(Panel.ZIndexProperty, 100); Target_Panel.Children.Add(Cntr); Grid.SetRow(Cntr, 0); Cntr.Margin = new Thickness( ((Target_Panel.ActualWidth / 2) - (Cntr.Width / 2)), ((Target_Panel.ActualHeight / 2) - (Cntr.Height / 2)), 0, 0); XPorter.Bus.Main_Handle.MainMenu.IsEnabled = false; XPorter.Bus.Main_Handle.Sidebar.IsEnabled = false; XPorter.Bus.Inner_Height = Target_Panel.ActualHeight - Cntr.Height - 1; XPorter.Bus.Inner_Width = Target_Panel.ActualWidth - Cntr.Width; VisualEffectsAndComponents.MainWindowVisualEffects.Curtain.Load_Curtain.IsHitTestVisible = false; VisualEffectsAndComponents.Connector.Cntr.Unloaded += delegate(object _object, RoutedEventArgs _e) { Target_Panel.Children.Remove(VisualEffectsAndComponents.MainWindowVisualEffects.Curtain.Load_Curtain); //delete curtain fx after destroying VisualEffectsAndComponents.MainWindowVisualEffects.Curtain.Load_Curtain = null; if (VisualEffectsAndComponents.Connector.Cntr != null) { VisualEffectsAndComponents.Connector.Cntr = null; } Target_Panel.SizeChanged -= target_panel_resize; }; Cntr.Loaded += delegate(object s, RoutedEventArgs ee) { var element = ((FrameworkElement)Cntr.Template.FindName("DockHeader", Cntr)); element.MouseLeftButtonDown += dock_panel_prev_mouse_down; //add listener functions for move element.MouseLeftButtonUp += dock_panel_Prev_mouse_up; element.MouseMove += dock_panel_prev_mouse_move; ((Button)Cntr.Template.FindName("Cancel", Cntr)).Click += cn_cancel_click; //destroy form button ((Button)Cntr.Template.FindName("Connect", Cntr)).Click += cn_connect_click; Target_Panel.SizeChanged += target_panel_resize; Old_Height = Target_Panel.ActualHeight - Cntr.ActualHeight; Old_Width = Target_Panel.ActualWidth - Cntr.ActualWidth; }; }
private void show_settings(object sender, RoutedEventArgs e) { if (Settings == null) { Settings = new ContentControl(); var tab = uni_tab_creator("Settings", true); var grid = new Grid(); grid.Background = System.Windows.Media.Brushes.AliceBlue; Uri _uri = new Uri(RCResourceLibs.vsresources.settings_style, UriKind.Relative); ResourceDictionary local_dict = new ResourceDictionary(); using (MemoryStream tmp_stream = new MemoryStream(Encoding.UTF8.GetBytes(_uri.ToString()))) { System.Windows.Markup.XamlReader reader = new System.Windows.Markup.XamlReader(); try { local_dict.MergedDictionaries.Add((ResourceDictionary)reader.LoadAsync(tmp_stream)); Settings.Resources = local_dict; } catch (Exception ex) { } } Uri uri = new Uri(RCResourceLibs.vsresources.win_settings, UriKind.Relative); //ResourceDictionary dict_res = new ResourceDictionary(); using (MemoryStream tmp_stream = new MemoryStream(Encoding.UTF8.GetBytes(uri.ToString()))) { System.Windows.Markup.XamlReader xaml_reader = new System.Windows.Markup.XamlReader(); try { local_dict.MergedDictionaries.Add((ResourceDictionary)xaml_reader.LoadAsync(tmp_stream)); } catch (Exception ex) { } Settings.Resources = local_dict; Settings.SetValue(Panel.ZIndexProperty, 110); grid.Children.Add(Settings); tab.Content = grid; } tab.Loaded += delegate { ((TabItem)Settings.Template.FindName("General", Settings)).PreviewMouseLeftButtonDown += label_click; ((TabItem)Settings.Template.FindName("Sounds", Settings)).PreviewMouseLeftButtonDown += label_click; ((TabItem)Settings.Template.FindName("Video", Settings)).PreviewMouseLeftButtonDown += label_click; ((TabItem)Settings.Template.FindName("Privacy", Settings)).PreviewMouseLeftButtonDown += label_click; ((TabItem)Settings.Template.FindName("Notifications", Settings)).PreviewMouseLeftButtonDown += label_click; ((TabItem)Settings.Template.FindName("Advanced", Settings)).PreviewMouseLeftButtonDown += label_click; TabSettings = (TabControl)Settings.Template.FindName("Settings", Settings); ((Button)Settings.Template.FindName("Default_General1", Settings)).Click += delegate { RCConnectLibrary.set_default_settings(); //refresh all settings values }; ((Button)Settings.Template.FindName("Default_General2", Settings)).Click += delegate { RCConnectLibrary.set_default_settings(); //refresh all settings values }; ((Button)Settings.Template.FindName("Apply_General1", Settings)).Click += delegate { GlobalTypes.Settings.IPCatalog.Clear(); GlobalTypes.Settings.IPCatalog.Add(new GlobalTypes.IPInterval( ((TextBox)Settings.Template.FindName("Left_Range_Ip", Settings)).Text, ((TextBox)Settings.Template.FindName("Left_Range_Ip", Settings)).Text )); if (((PasswordBox)Settings.Template.FindName("Password", Settings)).Password == ((PasswordBox)Settings.Template.FindName("Confirm_Password", Settings)).Password) { StatusBarText.Text = "Password Accepted"; GlobalTypes.Settings.Password = ((PasswordBox)Settings.Template.FindName("Password", Settings)).Password; } else { StatusBarText.Text = "Passwords doesn't equals"; } GlobalTypes.Settings.TabHeader = ((ComboBoxItem)((ComboBox)Settings.Template.FindName("Host_Name_Format", Settings)).SelectedItem).Content.ToString(); }; ((Button)Settings.Template.FindName("Apply_General2", Settings)).Click += delegate { GlobalTypes.Settings.TCPPort = Convert.ToInt32(((TextBox)Settings.Template.FindName("TCP_Port", Settings)).Text); GlobalTypes.Settings.Interval = Convert.ToInt32(((Slider)Settings.Template.FindName("Refresh_Period", Settings)).Value); GlobalTypes.Settings.TimeToConnect = Convert.ToInt32(((TextBox)Settings.Template.FindName("Connection_Timeout", Settings)).Text); GlobalTypes.Settings.ThreadCount = Convert.ToInt32(((Slider)Settings.Template.FindName("Thread_Count", Settings)).Value); }; }; tab.Unloaded += delegate { Settings = null; }; } else { foreach (TabItem it in MainTab.Items) { if (it.Header == "Settings") { MainTab.SelectedItem = it; } } } }
private void AddThemeResource(List<Mubox.View.Themes.ThemeDescriptor> themesList, string themeName) { try { var uri = new Uri("pack://siteoforigin:,,,/View/Themes/" + themeName + ".xaml", UriKind.Absolute); var resourceInfo = Application.GetRemoteStream(uri); var reader = new System.Windows.Markup.XamlReader(); ResourceDictionary resourceDictionary = (ResourceDictionary)reader.LoadAsync(resourceInfo.Stream); Mubox.View.Themes.ThemeDescriptor theme = new Mubox.View.Themes.ThemeDescriptor { Name = themeName, Resources = resourceDictionary }; themesList.Add(theme); if (Mubox.Configuration.MuboxConfigSection.Default.PreferredTheme == themeName) { Application.Current.Resources.MergedDictionaries.Add(theme.Resources); comboThemeSelector.SelectedItem = theme; } } catch (Exception ex) { ex.Log(); } }