Initial push
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using System.Reactive.Linq;
|
||||
using Avalonia.Media;
|
||||
|
||||
namespace SimpleNote;
|
||||
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
private MainViewModel ViewModel;
|
||||
public MainWindow(string[]? args)
|
||||
{
|
||||
if (args == null || args.Length < 1)
|
||||
{
|
||||
Console.WriteLine("Call with Note as Argument!");
|
||||
Environment.Exit(1);
|
||||
}
|
||||
InitializeComponent();
|
||||
ViewModel = new MainViewModel();
|
||||
DataContext = ViewModel;
|
||||
|
||||
this.GetObservable(Window.WidthProperty)
|
||||
.Subscribe(width =>
|
||||
{
|
||||
if (DataContext is MainViewModel vm)
|
||||
{
|
||||
vm.WindowWidth = (double)width;
|
||||
}
|
||||
});
|
||||
|
||||
init_TextField(args[0]);
|
||||
}
|
||||
|
||||
public void init_TextField(string text)
|
||||
{
|
||||
var textBlock = new TextBlock
|
||||
{
|
||||
Text = text,
|
||||
FontSize = ViewModel.FontSize,
|
||||
FontFamily = new FontFamily(FontFamily.DefaultFontFamilyName)
|
||||
};
|
||||
textBlock.Measure(Size.Infinity);
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user