public static void SetItemButtonImage(ContentControl control, MCItemLocator locator) { if (!File.Exists(locator.ImageFilePath)) { return; } Uri uriSource = new Uri(locator.ImageFilePath); if (control.Content == null) { control.Content = new Image(); } if (control.Content is Image image) { if (!(image.Source is BitmapImage bitmap)) { bitmap = new BitmapImage(uriSource) { CacheOption = BitmapCacheOption.OnLoad }; image.Source = bitmap; } bitmap.UriSource = uriSource; } }
private void BlockEditForm_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { if (DataContext is Block block) { MCItemLocator[] locators = MCItemLocator.GetAllMinecraftItems(); MCItemLocator inventoryTextureLocator = locators.FirstOrDefault(x => x.Name == block.InventoryTextureName); MCItemLocator textureLocator = locators.FirstOrDefault(x => x.Name == block.TextureName); StaticCommands.SetItemButtonImage(InventoryTextureButton, inventoryTextureLocator); StaticCommands.SetItemButtonImage(TextureButton, textureLocator); } }