public void UpdateMainWindowIcons(double margin) { // adapter.query below caused unhandled exception with main.selectedID as 0. if (adapter == null || main.selectedID == 0) { return; } // Convert to background worker here var container = adapter.Query(string.Format("SELECT `SpellIconID`,`ActiveIconID` FROM `{0}` WHERE `ID` = '{1}'", "spell", main.selectedID)); if (container == null || container.Rows.Count == 0) { return; } var res = container.Rows[0]; uint iconInt = uint.Parse(res[0].ToString()); uint iconActiveInt = uint.Parse(res[1].ToString()); // Update currently selected icon, we don't currently handle ActiveIconID main.CurrentIcon.Source = BlpManager.GetInstance().GetImageSourceFromBlpPath(GetIconPath(iconInt) + ".blp"); // Load all icons available if we have not already if (main.IconGrid.Children.Count == 0) { var watch = new Stopwatch(); watch.Start(); LoadAllIcons(margin); watch.Stop(); Logger.Info($"Loaded all icons as UI elements in {watch.ElapsedMilliseconds}ms"); } }
public void UpdateMainWindowIcons(double margin) { // adapter.query below caused unhandled exception with main.selectedID as 0. if (adapter == null || main.selectedID == 0) return; // Convert to background worker here DataRow res = adapter.Query(string.Format("SELECT `SpellIconID`,`ActiveIconID` FROM `{0}` WHERE `ID` = '{1}'", "spell", main.selectedID)).Rows[0]; uint iconInt = uint.Parse(res[0].ToString()); uint iconActiveInt = uint.Parse(res[1].ToString()); // Update currently selected icon, we don't currently use ActiveIconID System.Windows.Controls.Image temp = new System.Windows.Controls.Image(); temp.Width = iconSize == null ? 32 : iconSize.Value; temp.Height = iconSize == null ? 32 : iconSize.Value; temp.Margin = iconMargin == null ? new Thickness(margin, 0, 0, 0) : iconMargin.Value; temp.VerticalAlignment = VerticalAlignment.Top; temp.HorizontalAlignment = HorizontalAlignment.Left; temp.Source = BlpManager.GetInstance().GetImageSourceFromBlpPath(GetIconPath(iconInt) + ".blp"); temp.Name = "CurrentSpellIcon"; // Code smells here on hacky positioning and updating the icon temp.Margin = new Thickness(103, 38, 0, 0); main.CurrentIconGrid.Children.Clear(); main.CurrentIconGrid.Children.Add(temp); // Load all icons available if have not already if (main.IconGrid.Children.Count == 0) { var watch = new Stopwatch(); watch.Start(); LoadAllIcons(margin); watch.Stop(); Console.WriteLine($"Loaded all icons as UI elements in {watch.ElapsedMilliseconds}ms"); } }
private async void IsImageVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) { var image = sender as Image; var source = image.Source; if (source == null && (bool)e.NewValue) { var path = image.ToolTip.ToString().Substring(image.ToolTip.ToString().IndexOf('-') + 2); await Task.Factory.StartNew(() => source = BlpManager.GetInstance().GetImageSourceFromBlpPath(path)); } image.Source = source; }