made some minor changes
This commit is contained in:
+1
-1
@@ -16,7 +16,7 @@ public partial class App : Application
|
|||||||
{
|
{
|
||||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||||
{
|
{
|
||||||
desktop.MainWindow = new MainWindow(desktop.Args);
|
desktop.MainWindow = new MainWindow();
|
||||||
}
|
}
|
||||||
base.OnFrameworkInitializationCompleted();
|
base.OnFrameworkInitializationCompleted();
|
||||||
}
|
}
|
||||||
|
|||||||
+77
-48
@@ -5,58 +5,87 @@
|
|||||||
xmlns:vm="clr-namespace:SimpleNote"
|
xmlns:vm="clr-namespace:SimpleNote"
|
||||||
mc:Ignorable="d" d:DesignWidth="40" d:DesignHeight="200"
|
mc:Ignorable="d" d:DesignWidth="40" d:DesignHeight="200"
|
||||||
x:Class="SimpleNote.MainWindow"
|
x:Class="SimpleNote.MainWindow"
|
||||||
x:DataType="vm:MainViewModel"
|
x:DataType="vm:ViewModel"
|
||||||
WindowStartupLocation="CenterScreen"
|
WindowStartupLocation="Manual"
|
||||||
TransparencyLevelHint="AcrylicBlur"
|
TransparencyLevelHint="Transparent"
|
||||||
|
TransparencyBackgroundFallback="DimGray"
|
||||||
Background="Transparent"
|
Background="Transparent"
|
||||||
Height="50"
|
Height="50"
|
||||||
Width="{Binding WindowWidth}"
|
|
||||||
SystemDecorations="None"
|
SystemDecorations="None"
|
||||||
ExtendClientAreaToDecorationsHint="False"
|
ExtendClientAreaToDecorationsHint="True"
|
||||||
CanResize="False"
|
CanResize="False"
|
||||||
Topmost="True"
|
Topmost="True"
|
||||||
Title="SimpleNote">
|
Title="SimpleNote">
|
||||||
|
<Window.Styles>
|
||||||
<Panel>
|
<Style Selector="TextBox">
|
||||||
<ExperimentalAcrylicBorder IsHitTestVisible="False">
|
<Style Selector="^:focus">
|
||||||
<ExperimentalAcrylicBorder.Material>
|
<Setter Property="BorderBrush" Value="Transparent"/>
|
||||||
<ExperimentalAcrylicMaterial
|
<Style Selector="^ /template/ Border#PART_BorderElement">
|
||||||
BackgroundSource="Digger"
|
<Setter Property="Background" Value="Transparent"/>
|
||||||
TintColor="Black"
|
<Setter Property="BorderBrush" Value="Transparent"/>
|
||||||
TintOpacity="0.6"
|
<Setter Property="BorderThickness" Value="1" />
|
||||||
MaterialOpacity="0.65" />
|
</Style>
|
||||||
</ExperimentalAcrylicBorder.Material>
|
</Style>
|
||||||
</ExperimentalAcrylicBorder>
|
<Style Selector="^:pointerover /template/ Border#PART_BorderElement">
|
||||||
<TextBox HorizontalAlignment="Center"
|
<Setter Property="BorderBrush" Value="Transparent"/>
|
||||||
VerticalAlignment="Top"
|
<Setter Property="Background" Value="Transparent" />
|
||||||
Height="5"
|
</Style>
|
||||||
IsHitTestVisible="False"
|
</Style>
|
||||||
Margin="0, -3, 0, 0"
|
</Window.Styles>
|
||||||
Foreground="Black"
|
<!--<Border CornerRadius="15" BorderBrush="White" BorderThickness="2" Background="#000000aa">-->
|
||||||
Text="SimpleNote - Note"
|
<StackPanel Orientation="Horizontal">
|
||||||
Background="Transparent"
|
<ExperimentalAcrylicBorder IsHitTestVisible="False">
|
||||||
BorderThickness="0"
|
<ExperimentalAcrylicBorder.Material>
|
||||||
FontSize="12"
|
<ExperimentalAcrylicMaterial
|
||||||
IsTabStop="False"
|
BackgroundSource="Digger"
|
||||||
IsReadOnly="True"
|
TintColor="Green"
|
||||||
>
|
TintOpacity="0.5"
|
||||||
</TextBox>
|
MaterialOpacity="0.65" />
|
||||||
<TextBox x:Name="Note"
|
</ExperimentalAcrylicBorder.Material>
|
||||||
Height="20"
|
</ExperimentalAcrylicBorder>
|
||||||
BorderThickness="0"
|
<TextBox x:Name="FocusBox" IsVisible="False"/>
|
||||||
Width="{Binding WindowWidth}"
|
<Button Margin="5,0" Command="{Binding AddButtonPressedCommand}" FontSize="{Binding FontSize}" Width="40" HorizontalContentAlignment="Center">
|
||||||
Margin="0, 12, 0, 0"
|
+
|
||||||
Padding="5,0,5,0"
|
</Button>
|
||||||
TextAlignment="Center"
|
<ItemsControl ItemsSource="{Binding Notes}">
|
||||||
HorizontalAlignment="Center"
|
<ItemsControl.ItemsPanel>
|
||||||
VerticalAlignment="Center"
|
<ItemsPanelTemplate>
|
||||||
Foreground="White"
|
<StackPanel Orientation="Horizontal"/>
|
||||||
Background="Transparent"
|
</ItemsPanelTemplate>
|
||||||
IsHitTestVisible="False"
|
</ItemsControl.ItemsPanel>
|
||||||
FontSize="{Binding FontSize}"
|
<ItemsControl.ItemTemplate>
|
||||||
IsTabStop="False"
|
<DataTemplate x:DataType="vm:Note">
|
||||||
IsReadOnly="True"
|
<Border CornerRadius="15" Margin="5,5,0,5" BorderBrush="#fff" BorderThickness="2" Background="Transparent">
|
||||||
>
|
<StackPanel Margin="5" Background="Transparent" Orientation="Horizontal">
|
||||||
</TextBox>
|
<TextBox Height="20"
|
||||||
</Panel>
|
CaretBrush="Transparent"
|
||||||
|
BorderThickness="0"
|
||||||
|
Width="{Binding Width}"
|
||||||
|
TextChanged="TextBox_OnTextChanged"
|
||||||
|
Margin="0, 0, 0, 0"
|
||||||
|
Padding="5,0,5,0"
|
||||||
|
TextAlignment="Center"
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
Foreground="White"
|
||||||
|
Background="Transparent"
|
||||||
|
IsHitTestVisible="True"
|
||||||
|
FontSize="{Binding FontSize}"
|
||||||
|
IsTabStop="False"
|
||||||
|
IsReadOnly="False"
|
||||||
|
Text="{Binding Content}"
|
||||||
|
VerticalContentAlignment="Center"
|
||||||
|
KeyDown="InputElement_OnKeyDown"
|
||||||
|
>
|
||||||
|
</TextBox>
|
||||||
|
<Button Command="{Binding RemoveButtonClicked}" FontSize="{Binding FontSize}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Width="25" Padding="1,-3,0,0" Margin="5,0,0,0">
|
||||||
|
x
|
||||||
|
</Button>
|
||||||
|
</StackPanel>
|
||||||
|
</Border>
|
||||||
|
</DataTemplate>
|
||||||
|
</ItemsControl.ItemTemplate>
|
||||||
|
</ItemsControl>
|
||||||
|
</StackPanel>
|
||||||
|
<!--</Border>-->
|
||||||
</Window>
|
</Window>
|
||||||
|
|||||||
+44
-29
@@ -3,74 +3,89 @@ using System.ComponentModel;
|
|||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using System.Reactive.Linq;
|
using System.Reactive.Linq;
|
||||||
|
using Avalonia.Input;
|
||||||
|
using Avalonia.Interactivity;
|
||||||
using Avalonia.Media;
|
using Avalonia.Media;
|
||||||
|
|
||||||
namespace SimpleNote;
|
namespace SimpleNote;
|
||||||
|
|
||||||
public partial class MainWindow : Window
|
public partial class MainWindow : Window
|
||||||
{
|
{
|
||||||
private MainViewModel ViewModel;
|
private ViewModel viewModel;
|
||||||
public MainWindow(string[]? args)
|
private PixelRect? screen;
|
||||||
|
public MainWindow()
|
||||||
{
|
{
|
||||||
if (args == null || args.Length < 1)
|
screen = Screens.Primary?.WorkingArea;
|
||||||
|
if (screen == null)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Call with Note as Argument!");
|
Console.WriteLine("No screen available.");
|
||||||
Environment.Exit(1);
|
Environment.Exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.Position = new PixelPoint(screen.Value.Width / 2 - 25, 10);
|
||||||
|
this.Width = 50;
|
||||||
|
// this.MaxWidth = screen.Value.Width - 100;
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
ViewModel = new MainViewModel();
|
viewModel = new ViewModel();
|
||||||
DataContext = ViewModel;
|
DataContext = viewModel;
|
||||||
|
|
||||||
this.GetObservable(Window.WidthProperty)
|
this.GetObservable(Window.WidthProperty)
|
||||||
.Subscribe(width =>
|
.Subscribe(width =>
|
||||||
{
|
{
|
||||||
if (DataContext is MainViewModel vm)
|
if (DataContext is ViewModel vm)
|
||||||
{
|
{
|
||||||
vm.WindowWidth = (double)width;
|
vm.WindowWidth = (double)width;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
init_TextField(args[0]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
public void init_TextField(string text)
|
public void init_TextField(string text)
|
||||||
{
|
{
|
||||||
var textBlock = new TextBlock
|
var textBlock = new TextBlock
|
||||||
{
|
{
|
||||||
Text = text,
|
Text = text,
|
||||||
FontSize = ViewModel.FontSize,
|
FontSize = viewModel.FontSize,
|
||||||
FontFamily = new FontFamily(FontFamily.DefaultFontFamilyName)
|
FontFamily = new FontFamily(FontFamily.DefaultFontFamilyName)
|
||||||
};
|
};
|
||||||
textBlock.Measure(Size.Infinity);
|
textBlock.Measure(Size.Infinity);
|
||||||
ViewModel.WindowWidth = textBlock.DesiredSize.Width + 50;
|
viewModel.WindowWidth = textBlock.DesiredSize.Width + 50;
|
||||||
Note.Text = text;
|
Note.Text = text;
|
||||||
}
|
}
|
||||||
}
|
*/
|
||||||
|
|
||||||
public class MainViewModel : INotifyPropertyChanged
|
public static double TextWidth(string text)
|
||||||
{
|
|
||||||
private double _windowWidth = 200;
|
|
||||||
private double _fontSize = 24;
|
|
||||||
|
|
||||||
public double WindowWidth
|
|
||||||
{
|
{
|
||||||
get => _windowWidth;
|
var textBlock = new TextBlock
|
||||||
set
|
|
||||||
{
|
{
|
||||||
_windowWidth = value;
|
Text = text,
|
||||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(WindowWidth)));
|
FontSize = ViewModel._fontSize,
|
||||||
}
|
FontFamily = new FontFamily(FontFamily.DefaultFontFamilyName)
|
||||||
|
};
|
||||||
|
textBlock.Measure(Size.Infinity);
|
||||||
|
return textBlock.DesiredSize.Width + 30 < 60 ? 60 : textBlock.DesiredSize.Width + 30;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double FontSize
|
private void TextBox_OnTextChanged(object? sender, TextChangedEventArgs e)
|
||||||
{
|
{
|
||||||
get => _fontSize;
|
if (sender == null) return;
|
||||||
set
|
((TextBox)sender).Width = TextWidth(((TextBox)sender).Text);
|
||||||
|
double width = 55;
|
||||||
|
foreach (var note in viewModel.Notes)
|
||||||
{
|
{
|
||||||
_fontSize = value;
|
width += note.Width + 49;
|
||||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(FontSize)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (width == 55) width -= 5;
|
||||||
|
|
||||||
|
this.Width = width;
|
||||||
|
this.Position = new PixelPoint((int)((screen.Value.Width - width) / 2), 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
public event PropertyChangedEventHandler? PropertyChanged;
|
private void InputElement_OnKeyDown(object? sender, KeyEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Key == Key.Enter)
|
||||||
|
this.Focus();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+6
-5
@@ -9,12 +9,13 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Avalonia" Version="11.1.0" />
|
<PackageReference Include="Avalonia" Version="11.2.3" />
|
||||||
<PackageReference Include="Avalonia.Desktop" Version="11.1.0" />
|
<PackageReference Include="Avalonia.Desktop" Version="11.2.3" />
|
||||||
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.1.0" />
|
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.2.3" />
|
||||||
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.1.0" />
|
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.2.3" />
|
||||||
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
|
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
|
||||||
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.0" />
|
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.2.3" />
|
||||||
|
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
|
||||||
<PackageReference Include="System.Reactive.Linq" Version="6.0.1" />
|
<PackageReference Include="System.Reactive.Linq" Version="6.0.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
+115
@@ -0,0 +1,115 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using Avalonia.Interactivity;
|
||||||
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
using CommunityToolkit.Mvvm.Input;
|
||||||
|
|
||||||
|
namespace SimpleNote;
|
||||||
|
|
||||||
|
public class ViewModel : ObservableObject
|
||||||
|
{
|
||||||
|
private double _windowWidth = 200;
|
||||||
|
public static double _fontSize = 20;
|
||||||
|
private double _noteWidth;
|
||||||
|
|
||||||
|
public ObservableCollection<Note> Notes { get; set; } = new ObservableCollection<Note>();
|
||||||
|
public ICommand AddButtonPressedCommand { get; }
|
||||||
|
|
||||||
|
public ViewModel()
|
||||||
|
{
|
||||||
|
AddButtonPressedCommand = new RelayCommand(AddButtonPressedCommandEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double WindowWidth
|
||||||
|
{
|
||||||
|
get => _windowWidth;
|
||||||
|
set => SetProperty(ref _windowWidth, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double NoteWidth
|
||||||
|
{
|
||||||
|
get => _noteWidth;
|
||||||
|
set => SetProperty(ref _noteWidth, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double FontSize
|
||||||
|
{
|
||||||
|
get => _fontSize;
|
||||||
|
set => SetProperty(ref _fontSize, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddButtonPressedCommandEvent(object? sender)
|
||||||
|
{
|
||||||
|
// TODO: generate new Note
|
||||||
|
AddNote();
|
||||||
|
}
|
||||||
|
|
||||||
|
//[RelayCommand]
|
||||||
|
private void AddNote()
|
||||||
|
{
|
||||||
|
// Füge eine neue Note zur Collection hinzu
|
||||||
|
Note note = new Note
|
||||||
|
{
|
||||||
|
Width = MainWindow.TextWidth("New Note"), Content = "New Note", FontSize = FontSize,
|
||||||
|
};
|
||||||
|
note.RemoveButtonClicked = new RelayCommand(o => RemoveNote(note));
|
||||||
|
Notes.Add(note);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RemoveNote(Note note)
|
||||||
|
{
|
||||||
|
if (Notes.Contains(note))
|
||||||
|
{
|
||||||
|
Notes.Remove(note);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public event PropertyChangedEventHandler? PropertyChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Note : ObservableObject
|
||||||
|
{
|
||||||
|
public double Width { get; set; }
|
||||||
|
public string _content;
|
||||||
|
public double FontSize { get; set; }
|
||||||
|
public RelayCommand RemoveButtonClicked { get; set; }
|
||||||
|
|
||||||
|
public string Content
|
||||||
|
{
|
||||||
|
get => _content;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_content = value;
|
||||||
|
Width = MainWindow.TextWidth(_content);
|
||||||
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Content)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public event PropertyChangedEventHandler? PropertyChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class RelayCommand : ICommand
|
||||||
|
{
|
||||||
|
private readonly Action<object?> _execute;
|
||||||
|
private readonly Func<object?, bool>? _canExecute;
|
||||||
|
|
||||||
|
public event EventHandler? CanExecuteChanged;
|
||||||
|
|
||||||
|
public RelayCommand(Action<object?> execute, Func<object?, bool>? canExecute = null)
|
||||||
|
{
|
||||||
|
_execute = execute ?? throw new ArgumentNullException(nameof(execute));
|
||||||
|
_canExecute = canExecute;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool CanExecute(object? parameter) =>
|
||||||
|
_canExecute?.Invoke(parameter) ?? true;
|
||||||
|
|
||||||
|
public void Execute(object? parameter) =>
|
||||||
|
_execute(parameter);
|
||||||
|
|
||||||
|
public void RaiseCanExecuteChanged() =>
|
||||||
|
CanExecuteChanged?.Invoke(this, EventArgs.Empty);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user