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)
|
||||
{
|
||||
desktop.MainWindow = new MainWindow(desktop.Args);
|
||||
desktop.MainWindow = new MainWindow();
|
||||
}
|
||||
base.OnFrameworkInitializationCompleted();
|
||||
}
|
||||
|
||||
+59
-30
@@ -5,58 +5,87 @@
|
||||
xmlns:vm="clr-namespace:SimpleNote"
|
||||
mc:Ignorable="d" d:DesignWidth="40" d:DesignHeight="200"
|
||||
x:Class="SimpleNote.MainWindow"
|
||||
x:DataType="vm:MainViewModel"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
TransparencyLevelHint="AcrylicBlur"
|
||||
x:DataType="vm:ViewModel"
|
||||
WindowStartupLocation="Manual"
|
||||
TransparencyLevelHint="Transparent"
|
||||
TransparencyBackgroundFallback="DimGray"
|
||||
Background="Transparent"
|
||||
Height="50"
|
||||
Width="{Binding WindowWidth}"
|
||||
SystemDecorations="None"
|
||||
ExtendClientAreaToDecorationsHint="False"
|
||||
ExtendClientAreaToDecorationsHint="True"
|
||||
CanResize="False"
|
||||
Topmost="True"
|
||||
Title="SimpleNote">
|
||||
|
||||
<Panel>
|
||||
<Window.Styles>
|
||||
<Style Selector="TextBox">
|
||||
<Style Selector="^:focus">
|
||||
<Setter Property="BorderBrush" Value="Transparent"/>
|
||||
<Style Selector="^ /template/ Border#PART_BorderElement">
|
||||
<Setter Property="Background" Value="Transparent"/>
|
||||
<Setter Property="BorderBrush" Value="Transparent"/>
|
||||
<Setter Property="BorderThickness" Value="1" />
|
||||
</Style>
|
||||
</Style>
|
||||
<Style Selector="^:pointerover /template/ Border#PART_BorderElement">
|
||||
<Setter Property="BorderBrush" Value="Transparent"/>
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
</Style>
|
||||
</Style>
|
||||
</Window.Styles>
|
||||
<!--<Border CornerRadius="15" BorderBrush="White" BorderThickness="2" Background="#000000aa">-->
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<ExperimentalAcrylicBorder IsHitTestVisible="False">
|
||||
<ExperimentalAcrylicBorder.Material>
|
||||
<ExperimentalAcrylicMaterial
|
||||
BackgroundSource="Digger"
|
||||
TintColor="Black"
|
||||
TintOpacity="0.6"
|
||||
TintColor="Green"
|
||||
TintOpacity="0.5"
|
||||
MaterialOpacity="0.65" />
|
||||
</ExperimentalAcrylicBorder.Material>
|
||||
</ExperimentalAcrylicBorder>
|
||||
<TextBox HorizontalAlignment="Center"
|
||||
VerticalAlignment="Top"
|
||||
Height="5"
|
||||
IsHitTestVisible="False"
|
||||
Margin="0, -3, 0, 0"
|
||||
Foreground="Black"
|
||||
Text="SimpleNote - Note"
|
||||
Background="Transparent"
|
||||
<TextBox x:Name="FocusBox" IsVisible="False"/>
|
||||
<Button Margin="5,0" Command="{Binding AddButtonPressedCommand}" FontSize="{Binding FontSize}" Width="40" HorizontalContentAlignment="Center">
|
||||
+
|
||||
</Button>
|
||||
<ItemsControl ItemsSource="{Binding Notes}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<StackPanel Orientation="Horizontal"/>
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate x:DataType="vm:Note">
|
||||
<Border CornerRadius="15" Margin="5,5,0,5" BorderBrush="#fff" BorderThickness="2" Background="Transparent">
|
||||
<StackPanel Margin="5" Background="Transparent" Orientation="Horizontal">
|
||||
<TextBox Height="20"
|
||||
CaretBrush="Transparent"
|
||||
BorderThickness="0"
|
||||
FontSize="12"
|
||||
IsTabStop="False"
|
||||
IsReadOnly="True"
|
||||
>
|
||||
</TextBox>
|
||||
<TextBox x:Name="Note"
|
||||
Height="20"
|
||||
BorderThickness="0"
|
||||
Width="{Binding WindowWidth}"
|
||||
Margin="0, 12, 0, 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="False"
|
||||
IsHitTestVisible="True"
|
||||
FontSize="{Binding FontSize}"
|
||||
IsTabStop="False"
|
||||
IsReadOnly="True"
|
||||
IsReadOnly="False"
|
||||
Text="{Binding Content}"
|
||||
VerticalContentAlignment="Center"
|
||||
KeyDown="InputElement_OnKeyDown"
|
||||
>
|
||||
</TextBox>
|
||||
</Panel>
|
||||
<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>
|
||||
|
||||
+54
-39
@@ -3,74 +3,89 @@ using System.ComponentModel;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using System.Reactive.Linq;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Media;
|
||||
|
||||
namespace SimpleNote;
|
||||
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
private MainViewModel ViewModel;
|
||||
public MainWindow(string[]? args)
|
||||
private ViewModel viewModel;
|
||||
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);
|
||||
}
|
||||
|
||||
this.Position = new PixelPoint(screen.Value.Width / 2 - 25, 10);
|
||||
this.Width = 50;
|
||||
// this.MaxWidth = screen.Value.Width - 100;
|
||||
|
||||
InitializeComponent();
|
||||
ViewModel = new MainViewModel();
|
||||
DataContext = ViewModel;
|
||||
viewModel = new ViewModel();
|
||||
DataContext = viewModel;
|
||||
|
||||
this.GetObservable(Window.WidthProperty)
|
||||
.Subscribe(width =>
|
||||
{
|
||||
if (DataContext is MainViewModel vm)
|
||||
if (DataContext is ViewModel vm)
|
||||
{
|
||||
vm.WindowWidth = (double)width;
|
||||
}
|
||||
});
|
||||
|
||||
init_TextField(args[0]);
|
||||
}
|
||||
|
||||
/*
|
||||
public void init_TextField(string text)
|
||||
{
|
||||
var textBlock = new TextBlock
|
||||
{
|
||||
Text = text,
|
||||
FontSize = ViewModel.FontSize,
|
||||
FontSize = viewModel.FontSize,
|
||||
FontFamily = new FontFamily(FontFamily.DefaultFontFamilyName)
|
||||
};
|
||||
textBlock.Measure(Size.Infinity);
|
||||
ViewModel.WindowWidth = textBlock.DesiredSize.Width + 50;
|
||||
viewModel.WindowWidth = textBlock.DesiredSize.Width + 50;
|
||||
Note.Text = text;
|
||||
}
|
||||
}
|
||||
|
||||
public class MainViewModel : INotifyPropertyChanged
|
||||
{
|
||||
private double _windowWidth = 200;
|
||||
private double _fontSize = 24;
|
||||
|
||||
public double WindowWidth
|
||||
{
|
||||
get => _windowWidth;
|
||||
set
|
||||
{
|
||||
_windowWidth = value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(WindowWidth)));
|
||||
}
|
||||
}
|
||||
|
||||
public double FontSize
|
||||
{
|
||||
get => _fontSize;
|
||||
set
|
||||
{
|
||||
_fontSize = value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(FontSize)));
|
||||
}
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
*/
|
||||
|
||||
public static double TextWidth(string text)
|
||||
{
|
||||
var textBlock = new TextBlock
|
||||
{
|
||||
Text = text,
|
||||
FontSize = ViewModel._fontSize,
|
||||
FontFamily = new FontFamily(FontFamily.DefaultFontFamilyName)
|
||||
};
|
||||
textBlock.Measure(Size.Infinity);
|
||||
return textBlock.DesiredSize.Width + 30 < 60 ? 60 : textBlock.DesiredSize.Width + 30;
|
||||
}
|
||||
|
||||
private void TextBox_OnTextChanged(object? sender, TextChangedEventArgs e)
|
||||
{
|
||||
if (sender == null) return;
|
||||
((TextBox)sender).Width = TextWidth(((TextBox)sender).Text);
|
||||
double width = 55;
|
||||
foreach (var note in viewModel.Notes)
|
||||
{
|
||||
width += note.Width + 49;
|
||||
}
|
||||
|
||||
if (width == 55) width -= 5;
|
||||
|
||||
this.Width = width;
|
||||
this.Position = new PixelPoint((int)((screen.Value.Width - width) / 2), 10);
|
||||
}
|
||||
|
||||
private void InputElement_OnKeyDown(object? sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.Key == Key.Enter)
|
||||
this.Focus();
|
||||
}
|
||||
}
|
||||
+6
-5
@@ -9,12 +9,13 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Avalonia" Version="11.1.0" />
|
||||
<PackageReference Include="Avalonia.Desktop" Version="11.1.0" />
|
||||
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.1.0" />
|
||||
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.1.0" />
|
||||
<PackageReference Include="Avalonia" Version="11.2.3" />
|
||||
<PackageReference Include="Avalonia.Desktop" Version="11.2.3" />
|
||||
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.2.3" />
|
||||
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.2.3" />
|
||||
<!--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" />
|
||||
</ItemGroup>
|
||||
</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