mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-21 18:11:27 -07:00
Add icon preview to menu
This commit is contained in:
parent
eb6b5a7216
commit
72783ec391
@ -3,6 +3,7 @@ using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using Bloxstrap.Enums;
|
||||
using Bloxstrap.Helpers.Extensions;
|
||||
|
||||
namespace Bloxstrap.Dialogs
|
||||
{
|
||||
@ -46,7 +47,7 @@ namespace Bloxstrap.Dialogs
|
||||
this.BackColor = Color.FromArgb(25, 27, 29);
|
||||
}
|
||||
|
||||
this.IconBox.BackgroundImage = App.Settings.Prop.BootstrapperIcon.GetIconWithSize(new Size(128, 128)).ToBitmap();
|
||||
this.IconBox.BackgroundImage = App.Settings.Prop.BootstrapperIcon.GetIcon().GetSized(128, 128).ToBitmap();
|
||||
|
||||
SetupDialog();
|
||||
}
|
||||
|
@ -38,14 +38,5 @@ namespace Bloxstrap.Enums
|
||||
_ => Properties.Resources.IconBloxstrap
|
||||
};
|
||||
}
|
||||
|
||||
public static Icon GetIconWithSize(this BootstrapperIcon icon, Size size) => new(icon.GetIcon(), size);
|
||||
|
||||
public static ImageSource GetImageSource(this BootstrapperIcon icon)
|
||||
{
|
||||
using MemoryStream stream = new();
|
||||
icon.GetIcon().Save(stream);
|
||||
return BitmapFrame.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
19
Bloxstrap/Helpers/Extensions/IconEx.cs
Normal file
19
Bloxstrap/Helpers/Extensions/IconEx.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace Bloxstrap.Helpers.Extensions
|
||||
{
|
||||
public static class IconEx
|
||||
{
|
||||
public static Icon GetSized(this Icon icon, int width, int height) => new(icon, new Size(width, height));
|
||||
|
||||
public static ImageSource GetImageSource(this Icon icon)
|
||||
{
|
||||
using MemoryStream stream = new();
|
||||
icon.Save(stream);
|
||||
return BitmapFrame.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using Bloxstrap.Dialogs;
|
||||
using Bloxstrap.Enums;
|
||||
using Bloxstrap.Helpers.Extensions;
|
||||
using Bloxstrap.Views;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Wpf.Ui.Mvvm.Services;
|
||||
@ -15,8 +18,11 @@ using Wpf.Ui.Mvvm.Contracts;
|
||||
|
||||
namespace Bloxstrap.ViewModels
|
||||
{
|
||||
public class BootstrapperViewModel
|
||||
public class BootstrapperViewModel : INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
public void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
|
||||
private readonly Page _page;
|
||||
|
||||
public ICommand PreviewBootstrapperCommand => new RelayCommand(PreviewBootstrapper);
|
||||
@ -100,7 +106,13 @@ namespace Bloxstrap.ViewModels
|
||||
public string Icon
|
||||
{
|
||||
get => Icons.FirstOrDefault(x => x.Value == App.Settings.Prop.BootstrapperIcon).Key;
|
||||
set => App.Settings.Prop.BootstrapperIcon = Icons[value];
|
||||
set
|
||||
{
|
||||
App.Settings.Prop.BootstrapperIcon = Icons[value];
|
||||
OnPropertyChanged(nameof(IconPreviewSource));
|
||||
}
|
||||
}
|
||||
|
||||
public ImageSource IconPreviewSource => App.Settings.Prop.BootstrapperIcon.GetIcon().GetImageSource();
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ using System.Windows.Media;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Bloxstrap.Dialogs;
|
||||
using Bloxstrap.Enums;
|
||||
using Bloxstrap.Helpers.Extensions;
|
||||
|
||||
namespace Bloxstrap.ViewModels
|
||||
{
|
||||
@ -21,7 +22,7 @@ namespace Bloxstrap.ViewModels
|
||||
|
||||
public ICommand CancelInstallCommand => new RelayCommand(CancelInstall);
|
||||
|
||||
public ImageSource Icon { get; set; } = App.Settings.Prop.BootstrapperIcon.GetImageSource();
|
||||
public ImageSource Icon { get; set; } = App.Settings.Prop.BootstrapperIcon.GetIcon().GetImageSource();
|
||||
public string Message { get; set; } = "Please wait...";
|
||||
public bool ProgressIndeterminate { get; set; } = true;
|
||||
public int ProgressValue { get; set; } = 0;
|
||||
|
@ -6,7 +6,7 @@
|
||||
xmlns:models="clr-namespace:Bloxstrap.ViewModels"
|
||||
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800"
|
||||
d:DesignHeight="600" d:DesignWidth="800"
|
||||
Title="BootstrapperPage"
|
||||
Scrollable="True">
|
||||
|
||||
@ -69,7 +69,18 @@
|
||||
<TextBlock FontSize="12" Text="Choose what icon the bootstrapper should use." Foreground="{DynamicResource TextFillColorTertiaryBrush}" />
|
||||
</StackPanel>
|
||||
</ui:CardControl.Header>
|
||||
<ComboBox Width="200" Padding="10,5,10,5" ItemsSource="{Binding Icons.Keys, Mode=OneTime}" Text="{Binding Icon, Mode=TwoWay}" />
|
||||
<Grid Width="200">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Border Grid.Column="0" Width="28" Height="28" Margin="0,0,5,0">
|
||||
<Border.Background>
|
||||
<ImageBrush ImageSource="{Binding IconPreviewSource, Mode=OneWay}" />
|
||||
</Border.Background>
|
||||
</Border>
|
||||
<ComboBox Grid.Column="1" Margin="5,0,0,0" Padding="10,5,10,5" ItemsSource="{Binding Icons.Keys, Mode=OneTime}" Text="{Binding Icon, Mode=TwoWay}" />
|
||||
</Grid>
|
||||
</ui:CardControl>
|
||||
<ui:Button Content="Preview" HorizontalAlignment="Stretch" Margin="0,8,0,0" Command="{Binding PreviewBootstrapperCommand}" />
|
||||
</StackPanel>
|
||||
|
Loading…
Reference in New Issue
Block a user