private void CreateNewIcon()
        {
            if (Car == null)
            {
                return;
            }

            ValuesStorage.Set(_key, NewIconLabel.Text);
            // TODO: Save style?

            var size = new Size(CommonAcConsts.UpgradeIconWidth, CommonAcConsts.UpgradeIconHeight);

            NewIcon.Measure(size);
            NewIcon.Arrange(new Rect(size));
            NewIcon.ApplyTemplate();
            NewIcon.UpdateLayout();

            var bmp = new RenderTargetBitmap(CommonAcConsts.UpgradeIconWidth, CommonAcConsts.UpgradeIconHeight, 96, 96, PixelFormats.Pbgra32);

            bmp.Render(NewIcon);

            try {
                bmp.SaveTo(Car.UpgradeIcon);
                BetterImage.Refresh(Car.UpgradeIcon);
            } catch (IOException ex) {
                NonfatalError.Notify(AppStrings.UpgradeIcon_CannotChange, AppStrings.UpgradeIcon_CannotChange_Commentary, ex);
            } catch (Exception ex) {
                NonfatalError.Notify(AppStrings.UpgradeIcon_CannotChange, ex);
            }
        }
Exemple #2
0
        private void OnClosing(object sender, CancelEventArgs e)
        {
            if (!IsResultOk)
            {
                return;
            }

            foreach (var item in IconsList.FindVisualChildren <FrameworkElement>().Where(x => x.Name == @"NewIcon"))
            {
                if (!(item.DataContext is AppWindowItem data) || !data.IsInEditMode)
                {
                    continue;
                }

                item.DataContext = data;
                data.Save();
                var size   = new Size(CommonAcConsts.AppIconWidth, CommonAcConsts.AppIconHeight);
                var result = new ContentPresenter {
                    Width = size.Width, Height = size.Height, Content = item
                };

                SaveIcon();
                data.ShowEnabled = !data.ShowEnabled;
                SaveIcon();

                void SaveIcon()
                {
                    result.Measure(size);
                    result.Arrange(new Rect(size));
                    result.ApplyTemplate();
                    result.UpdateLayout();

                    var bmp = new RenderTargetBitmap(CommonAcConsts.AppIconWidth, CommonAcConsts.AppIconHeight, 96, 96, PixelFormats.Pbgra32);

                    bmp.Render(result);
                    bmp.SaveTo(data.IconOriginal);
                    BetterImage.Refresh(data.IconOriginal);
                }
            }
        }