Skip to content

Commit 9d76645

Browse files
committed
Created custom toast notification.
1 parent daf25bf commit 9d76645

6 files changed

Lines changed: 196 additions & 6 deletions

File tree

CutCode/ViewModels/MainViewModel.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ public class MainViewModel : Screen
2222
//private List<Button> leftBarBtns;
2323
public static List<Object> Pages;
2424
private readonly IThemeService _themeService;
25+
private IWindowManager windowManager;
2526
private readonly IPageService pageService;
2627
public ObservableCollection<SideBarBtnModel> sideBarBtns { get; set; }
27-
public MainViewModel(IThemeService themeService, IPageService _pageService, IDataBase _dataBase)
28+
public MainViewModel(IWindowManager _windowManager,IThemeService themeService, IPageService _pageService, IDataBase _dataBase)
2829
{
30+
windowManager = _windowManager;
31+
2932
_themeService = themeService;
3033
_themeService.ThemeChanged += ThemeChanged;
3134
_themeService.IsLightTheme = _dataBase.isLightTheme;
@@ -93,6 +96,11 @@ public void ChangePageCommand(string selected_item)
9396

9497
sideBarBtns[ind].background = _themeService.IsLightTheme ? ColorCon.Convert("#FCFCFC") : ColorCon.Convert("#36393F");
9598
if (currentPage != Pages[ind]) pageService.Page = Pages[ind];
99+
100+
if(selected_item == "Share")
101+
{
102+
windowManager.ShowDialog(new NotificationDialogViewModel(_themeService, "Just for test"));
103+
}
96104
}
97105

98106
#region Color
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using Stylet;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Windows.Media;
8+
9+
namespace CutCode
10+
{
11+
public class NotificationDialogViewModel : Screen
12+
{
13+
public NotificationDialogViewModel(IThemeService themeService, string _message)
14+
{
15+
message = _message;
16+
background = themeService.IsLightTheme ? ColorCon.Convert("#DCDCDC") : ColorCon.Convert("#26292F");
17+
exitBtnHoverColor = themeService.IsLightTheme ? ColorCon.Convert("#D0D1D2") : ColorCon.Convert("#1F232B");
18+
textColor = themeService.IsLightTheme ? ColorCon.Convert("#060607") : ColorCon.Convert("#94969A");
19+
exitImage = themeService.IsLightTheme ? "../Resources/Images/Icons/exit_black.png" : "../Resources/Images/Icons/exit_white.png";
20+
}
21+
22+
private string _exitImage;
23+
public string exitImage
24+
{
25+
get => _exitImage;
26+
set
27+
{ SetAndNotify(ref _exitImage, value); }
28+
}
29+
30+
private string _message;
31+
public string message
32+
{
33+
get => _message;
34+
set
35+
{ SetAndNotify(ref _message, value); }
36+
}
37+
38+
private SolidColorBrush _background;
39+
public SolidColorBrush background
40+
{
41+
get => _background;
42+
set
43+
{ SetAndNotify(ref _background, value); }
44+
}
45+
46+
private SolidColorBrush _textColor;
47+
public SolidColorBrush textColor
48+
{
49+
get => _textColor;
50+
set
51+
{
52+
if (value != _textColor)
53+
{
54+
SetAndNotify(ref _textColor, value);
55+
}
56+
}
57+
}
58+
59+
private SolidColorBrush _exitBtnHoverColor;
60+
public SolidColorBrush exitBtnHoverColor
61+
{
62+
get => _exitBtnHoverColor;
63+
set
64+
{
65+
if (value != _exitBtnHoverColor)
66+
{
67+
SetAndNotify(ref _exitBtnHoverColor, value);
68+
}
69+
}
70+
71+
}
72+
}
73+
}

CutCode/Views/MainView.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
<ItemsControl.ItemTemplate>
8585
<DataTemplate>
8686

87-
<Button Background="{Binding background}"
87+
<Button Background="{Binding background}" BorderThickness="0"
8888
Style="{StaticResource ImgButtonStyle}"
8989
Command="{s:Action ChangePageCommand}" CommandParameter="{Binding toolTipText}">
9090
<Image Source="{Binding imageSource}" Margin="15,10,10,10" VerticalAlignment="Top"

CutCode/Views/MainView.xaml.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ private void MaximizeClicked(object sender, RoutedEventArgs e)
4545
WindowState = WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
4646
}
4747

48-
private void ExitClicked(object sender, RoutedEventArgs e)
49-
{
50-
Close();
51-
}
48+
private void ExitClicked(object sender, RoutedEventArgs e) => Close();
5249
}
5350
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<Window x:Class="CutCode.NotificationDialogView"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:local="clr-namespace:CutCode"
7+
mc:Ignorable="d"
8+
d:DataContext="{d:DesignInstance local:NotificationDialogViewModel}"
9+
ResizeMode="NoResize"
10+
WindowStyle="SingleBorderWindow"
11+
UseLayoutRounding="True"
12+
Title="Notification" Height="50" Width="270">
13+
14+
<WindowChrome.WindowChrome>
15+
<WindowChrome GlassFrameThickness="0" CornerRadius="15" CaptionHeight="0" ResizeBorderThickness="5"/>
16+
</WindowChrome.WindowChrome>
17+
18+
<Window.Resources>
19+
<Style x:Key="ButtonStyle" TargetType="Button">
20+
<Setter Property="Template">
21+
<Setter.Value>
22+
<ControlTemplate TargetType="Button">
23+
<Border>
24+
<Border.Style>
25+
<Style TargetType="{x:Type Border}">
26+
<Style.Triggers>
27+
<Trigger Property="IsMouseOver" Value="True">
28+
<Setter Property="Background" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=BorderBrush}"/>
29+
<Setter Property="BorderBrush" Value="Transparent"/>
30+
</Trigger>
31+
</Style.Triggers>
32+
</Style>
33+
</Border.Style>
34+
<Grid Background="{TemplateBinding Background}">
35+
<ContentPresenter></ContentPresenter>
36+
</Grid>
37+
</Border>
38+
</ControlTemplate>
39+
</Setter.Value>
40+
</Setter>
41+
</Style>
42+
</Window.Resources>
43+
44+
<Grid Background="{Binding background}">
45+
<Grid.ColumnDefinitions>
46+
<ColumnDefinition Width="*"/>
47+
<ColumnDefinition Width="40"/>
48+
</Grid.ColumnDefinitions>
49+
50+
<Grid Grid.Column="0">
51+
<Grid.RowDefinitions>
52+
<RowDefinition Height="30"/>
53+
<RowDefinition Height="Auto"/>
54+
</Grid.RowDefinitions>
55+
<Label Grid.Row="0" FontSize="10.5" FontFamily="{StaticResource poppins_semibold}" Content="Notification" Foreground="{Binding textColor}"/>
56+
<Label Grid.Row="1" Foreground="{Binding textColor}" Content="{Binding message}" Margin="0,-12,0,0"
57+
FontSize="14" FontFamily="{StaticResource poppins_semibold}"/>
58+
</Grid>
59+
60+
<Button Grid.Column="1" Background="Transparent" Style="{DynamicResource ButtonStyle}"
61+
Click="exitBtnClick" BorderBrush="{Binding exitBtnHoverColor}" VerticalAlignment="Center">
62+
<Image Width="20" Height="20" Margin="4,15,4,15" Source="{Binding exitImage}"
63+
RenderOptions.BitmapScalingMode="HighQuality" RenderOptions.EdgeMode="Aliased"/>
64+
</Button>
65+
66+
</Grid>
67+
</Window>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Windows;
7+
using System.Windows.Controls;
8+
using System.Windows.Data;
9+
using System.Windows.Documents;
10+
using System.Windows.Forms;
11+
using System.Windows.Input;
12+
using System.Windows.Interop;
13+
using System.Windows.Media;
14+
using System.Windows.Media.Imaging;
15+
using System.Windows.Shapes;
16+
17+
namespace CutCode
18+
{
19+
/// <summary>
20+
/// Interaction logic for NotificationDialogView.xaml
21+
/// </summary>
22+
public partial class NotificationDialogView : Window
23+
{
24+
public NotificationDialogView()
25+
{
26+
InitializeComponent();
27+
28+
var mainView = System.Windows.Application.Current.Windows[0] as MainView;
29+
30+
if(mainView.WindowState == WindowState.Maximized)
31+
{
32+
var currentScreen = Screen.FromHandle(new WindowInteropHelper(mainView).Handle).Bounds;
33+
Top = currentScreen.Bottom - (Height + 50);
34+
Left = currentScreen.Right - (Width + 10);
35+
}
36+
else
37+
{
38+
Top = mainView.Top + mainView.Height - (Height + 10);
39+
Left = mainView.Left + mainView.Width - (Width + 10);
40+
}
41+
}
42+
43+
private void exitBtnClick(object sender, RoutedEventArgs e) => Close();
44+
}
45+
}

0 commit comments

Comments
 (0)