public static Window CreateWindow() { try { var filename = Path.Combine(FileManager.PluginPath, "UI", "TVars.xaml"); if (_window == null) { _window = new Window(); } _window.DataContext = new TVarsViewModel(); string content = File.ReadAllText(filename); UserControl userControl = UILoader.LoadAndTransformXamlFile <UserControl>(filename); _window.Content = userControl; _window.Height = 620; _window.Width = 600; _window.MinHeight = 580; _window.MinWidth = 600; _window.Title = "Trinity Variables"; _window.Closed += Window_Closed; } catch (Exception ex) { Logger.LogNormal("Unable to open Trinity Variables: {0}", ex.ToString()); } return(_window); }
public ConfigWindow(int heroId) { Height = 580; Width = 700; try { _mainControl = UILoader.LoadAndTransformXamlFile <UserControl>(Path.Combine(FileUtils.PluginPath, "UI", "Config.xaml")); } catch (Exception) { Logger.Error("Couldn't find the file {0}", Path.Combine(FileUtils.PluginPath, "UI", "Config.xaml")); return; } Content = _mainControl; //Title = "Adventurer Config for " + ZetaDia.Service.Hero.Name + " - " + ZetaDia.Service.Hero.Class; Title = "Adventurer SettingsStorage"; ResizeMode = ResizeMode.NoResize; //Top = Application.Current.MainWindow.Top + (Application.Current.MainWindow.Height - Height) / 2; //Left = Application.Current.MainWindow.Left + (Application.Current.MainWindow.Width - Width) / 2; if (Top < 0) { Top = 0; } _saveButton = LogicalTreeHelper.FindLogicalNode(_mainControl, "SaveButton") as Button; _saveButton.Click += SaveButton_Click; _cancelButton = LogicalTreeHelper.FindLogicalNode(_mainControl, "CancelButton") as Button; _cancelButton.Click += CancelButton_Click; _gemPriorityUp = LogicalTreeHelper.FindLogicalNode(_mainControl, "GemPriorityUp") as Button; _gemPriorityUp.Click += GemPriorityUp_Click; _gemPriorityDown = LogicalTreeHelper.FindLogicalNode(_mainControl, "GemPriorityDown") as Button; _gemPriorityDown.Click += GemPriorityDown_Click; _gemPriorityList = LogicalTreeHelper.FindLogicalNode(_mainControl, "GemPriorityList") as ListBox; _prioritizeEquippedGems = LogicalTreeHelper.FindLogicalNode(_mainControl, "GreaterRiftPrioritizeEquipedGems") as CheckBox; _prioritizeEquippedGems.Click += PrioritizeEquippedGems_Click; _greaterRiftLevel = LogicalTreeHelper.FindLogicalNode(_mainControl, "GreaterRiftLevel") as ComboBox; _greaterRiftLevel.SelectionChanged += GreaterRiftLevel_SelectionChanged; _bountyAct1 = LogicalTreeHelper.FindLogicalNode(_mainControl, "BountyAct1") as CheckBox; _bountyAct2 = LogicalTreeHelper.FindLogicalNode(_mainControl, "BountyAct2") as CheckBox; _bountyAct3 = LogicalTreeHelper.FindLogicalNode(_mainControl, "BountyAct3") as CheckBox; _bountyAct4 = LogicalTreeHelper.FindLogicalNode(_mainControl, "BountyAct4") as CheckBox; _bountyAct5 = LogicalTreeHelper.FindLogicalNode(_mainControl, "BountyAct5") as CheckBox; _bountyPrioritizeBonusAct = LogicalTreeHelper.FindLogicalNode(_mainControl, "BountyPrioritizeBonusAct") as CheckBox; _pluginSettings = PluginSettings.Current; DataContext = _pluginSettings; BattleNetHeroId = heroId; }
public MapWindow() { Height = 580; Width = 700; try { Content = UILoader.LoadAndTransformXamlFile <UserControl>(Path.Combine(FileUtils.PluginPath, "UI", "MapUI.xaml"));; } catch (Exception) { Content = UILoader.LoadAndTransformXamlFile <UserControl>(Path.Combine(FileUtils.PluginPath2, "UI", "MapUI.xaml"));; } Title = "MapUI Powered by Trinity"; }
public ConfigWindow() { UserControl mainControl; Height = 580; Width = 700; var path = Path.Combine(FileUtils.PluginPath, "Components", "Adventurer", "UI", "Config.xaml"); try { mainControl = UILoader.LoadAndTransformXamlFile <UserControl>(path); } catch (Exception) { Core.Logger.Error($"Couldn't find the file {path}"); return; } Content = mainControl; Title = "Adventurer Settings"; ResizeMode = ResizeMode.NoResize; if (Top < 0) { Top = 0; } var greaterRiftLevel = LogicalTreeHelper.FindLogicalNode(mainControl, "GreaterRiftLevel") as ComboBox; if (greaterRiftLevel != null) { greaterRiftLevel.SelectionChanged += GreaterRiftLevel_SelectionChanged; } _pluginSettings = PluginSettings.Current; DataContext = _pluginSettings; }
/// <summary> /// A window with its own UI Thread. /// </summary> public ThreadedWindow(string xamlPath, object dataContext, string name = "", int height = 0, int width = 0) { try { if (String.IsNullOrEmpty(xamlPath)) { throw new ArgumentException("xamlPath"); } if (dataContext == null) { throw new ArgumentException("dataContext"); } if (!File.Exists(xamlPath)) { throw new ArgumentException("xamlPath: file doesn't exist"); } _thread = new Thread(threadDataContext => { _window = new Window { Height = height > MinimumHeight ? height : 750, Width = height > MininumWidth ? width : 1200, MinHeight = MinimumHeight, MinWidth = MininumWidth, Title = name, Content = UILoader.LoadAndTransformXamlFile <UserControl>(xamlPath), DataContext = threadDataContext }; IsWindowCreated = true; Application.Current.Dispatcher.Invoke(() => { Application.Current.MainWindow.Closing += (sender, args) => { Logger.Log("ThreadedWindow: Closing {0} window ", name); _allowedToClose = true; _dispatcher.InvokeShutdown(); }; }); // Hide window instead of closing to avoid WPF thread ownership issues. _window.Closing += (sender, args) => { if (!_allowedToClose) { Logger.Log("ThreadedWindow: Hiding {0} window ", name); _window.Hide(); OnHidden(); args.Cancel = true; } _isWindowOpen = false; }; _window.ContentRendered += (sender, args) => { IsWindowLoaded = true; }; _window.Closed += (s, e) => { Logger.Log("ThreadedWindow: Shutting down {0} thread ", name); _window.Dispatcher.InvokeShutdown(); }; _window.WindowStartupLocation = WindowStartupLocation.CenterScreen; Dispatcher.Run(); }); // Single thread apartment prevents access to owned objects by other threads _thread.SetApartmentState(ApartmentState.STA); if (!String.IsNullOrEmpty(name)) { _thread.Name = name + " ThreadedWindow"; } _thread.Start(dataContext); _internalTimer.Tick += InternalTimerTick; _internalTimer.Interval = new TimeSpan(0, 0, 0, 1, 0); _internalTimer.Start(); } catch (Exception ex) { Logger.Log("Unable to create ThreadedWindow: {0}", ex); } }