Skip to content

Commit b91aaee

Browse files
committed
wip commit
1 parent 69c8a46 commit b91aaee

File tree

6 files changed

+123
-5
lines changed

6 files changed

+123
-5
lines changed

src/WEventViewer/App.axaml.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using Avalonia;
22
using Avalonia.Controls.ApplicationLifetimes;
33
using Avalonia.Markup.Xaml;
4+
using Microsoft.Extensions.DependencyInjection;
5+
using WEventViewer.ViewModel;
46

57
namespace WEventViewer;
68

@@ -13,6 +15,8 @@ public override void Initialize()
1315

1416
public override void OnFrameworkInitializationCompleted()
1517
{
18+
var collection = new ServiceCollection();
19+
1620
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
1721
{
1822
desktop.MainWindow = new MainWindow();

src/WEventViewer/MainWindow.axaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:vm="using:WEventViewer.ViewModel"
56
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
67
x:Class="WEventViewer.MainWindow"
78
Title="WEventViewer">
9+
<Design.DataContext>
10+
<vm:MainWindowViewModel></vm:MainWindowViewModel>
11+
</Design.DataContext>
812
<StackPanel Orientation="Vertical">
913
<Menu DockPanel.Dock="Top">
1014
<MenuItem Header="_File">
11-
<MenuItem Header="_Open"/>
15+
<MenuItem Header="_Open" Command="{Binding $parent.$parent.$parent.$parent.OpenCommand}"/>
1216
</MenuItem>
1317
<MenuItem Header="_About"/>
1418
</Menu>

src/WEventViewer/OpenLogWindow.axaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:vm="using:WEventViewer.ViewModel"
56
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
67
x:Class="WEventViewer.OpenLogWindow"
78
Title="OpenLogWindow">
8-
<StackPanel>
9-
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
9+
<Design.DataContext>
10+
<vm:OpenLogWindowViewModel/>
11+
</Design.DataContext>
12+
<StackPanel HorizontalAlignment="Stretch">
13+
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
1014
<Label Content="abc" Margin="10,10,10,10" HorizontalAlignment="Left"/>
11-
<TextBox Margin="10,10,10,10" Padding="50,0,0,0" HorizontalAlignment="Stretch"/>
15+
<TextBox Margin="10,10,10,10" Padding="50,0,0,0" HorizontalAlignment="Stretch" Text="{Binding $parent.$parent.LogName, Mode=TwoWay}"/>
1216
</StackPanel>
1317
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
1418
<Label Content="abc" Margin="10,10,10,10" HorizontalAlignment="Left"/>
15-
<TextBox Margin="10,10,10,10" Padding="200,0,0,0" HorizontalAlignment="Stretch"/>
19+
<TextBox Margin="10,10,10,10" Padding="0,0,0,0" HorizontalAlignment="Stretch"/>
1620
</StackPanel>
1721
</StackPanel>
1822
</Window>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Avalonia.Controls;
7+
using CommunityToolkit.Mvvm.Input;
8+
using CommunityToolkit.Mvvm.Messaging;
9+
using System.Windows.Input;
10+
using WEventViewer.Model;
11+
12+
namespace WEventViewer.ViewModel
13+
{
14+
internal class MainWindowViewModel
15+
{
16+
record class OpenLogMessage(MainWindowViewModel vm);
17+
EventLogRepository? _EventLogRepository;
18+
public MainWindowViewModel(): this(null)
19+
{
20+
}
21+
public MainWindowViewModel(EventLogRepository repository)
22+
{
23+
OpenCommand = new RelayCommand(() =>
24+
{
25+
var ret = WeakReferenceMessenger.Default.Send<OpenLogMessage>(new(this));
26+
});
27+
_EventLogRepository = repository;
28+
}
29+
public ICommand OpenCommand;
30+
}
31+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using Avalonia.Data.Converters;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.ComponentModel;
5+
using System.Diagnostics.Eventing.Reader;
6+
using System.Globalization;
7+
using System.Linq;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
11+
namespace WEventViewer.ViewModel
12+
{
13+
internal class PathTypeValueConverter : IValueConverter
14+
{
15+
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
16+
{
17+
if(value is PathType ptype)
18+
{
19+
if(targetType == typeof(string))
20+
{
21+
return ptype.ToString();
22+
}
23+
else if(targetType == typeof(int))
24+
{
25+
return (int)ptype;
26+
}
27+
}
28+
throw new ArgumentException($"Convert: unsupported type({value?.GetType()})");
29+
}
30+
31+
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
32+
{
33+
if(value is string s)
34+
{
35+
if(s.Equals(nameof(PathType.LogName), StringComparison.OrdinalIgnoreCase))
36+
{
37+
return PathType.LogName;
38+
}
39+
else if(s.Equals(nameof(PathType.FilePath), StringComparison.OrdinalIgnoreCase))
40+
{
41+
return PathType.FilePath;
42+
}
43+
}
44+
else if(value is int i)
45+
{
46+
return (PathType)i;
47+
}
48+
throw new ArgumentException($"ConvertBack: unsupported type({value?.GetType()})");
49+
}
50+
}
51+
internal class OpenLogWindowViewModel : INotifyPropertyChanged
52+
{
53+
string _LogName = "";
54+
public string LogName { get => _LogName; set
55+
{
56+
_LogName = value;
57+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(LogName)));
58+
}
59+
}
60+
PathType _PathType = PathType.LogName;
61+
public PathType PathType
62+
{
63+
get => _PathType;
64+
set
65+
{
66+
_PathType = value;
67+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(PathType)));
68+
}
69+
}
70+
71+
public event PropertyChangedEventHandler? PropertyChanged;
72+
}
73+
}

src/WEventViewer/WEventViewer.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.0.10" />
1717
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
1818
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.10" />
19+
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
20+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
1921
<PackageReference Include="System.Diagnostics.EventLog" Version="8.0.0" />
2022
</ItemGroup>
2123
</Project>

0 commit comments

Comments
 (0)