Working with warnings
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
</Application.DataTemplates>
|
||||
|
||||
<Application.Styles>
|
||||
<FluentTheme Mode="Light"/>
|
||||
<FluentTheme/>
|
||||
<StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Fluent.xaml"/>
|
||||
</Application.Styles>
|
||||
</Application>
|
||||
@@ -1,23 +1,23 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Data.Core;
|
||||
using Avalonia.Data.Core.Plugins;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using AvaloniaLoggingDI.ViewModels;
|
||||
using AvaloniaLoggingDI.Views;
|
||||
using LogViewer.Avalonia;
|
||||
using MessageBox.Avalonia;
|
||||
using MessageBox.Avalonia.Enums;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MsBox.Avalonia;
|
||||
using MsBox.Avalonia.Enums;
|
||||
using MsLogger.Core;
|
||||
using RandomLogging.Service;
|
||||
using Icon = MessageBox.Avalonia.Enums.Icon;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using Icon = MsBox.Avalonia.Enums.Icon;
|
||||
|
||||
namespace AvaloniaLoggingDI;
|
||||
|
||||
@@ -30,9 +30,9 @@ public partial class App : Application
|
||||
{
|
||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
// Line below is needed to remove Avalonia data validation.
|
||||
// Without this line you will get duplicate validations from both Avalonia and CT
|
||||
ExpressionObserver.DataValidators.RemoveAll(x => x is DataAnnotationsValidationPlugin);
|
||||
// Avoid duplicate validations from both Avalonia and the CommunityToolkit.
|
||||
// More info: https://docs.avaloniaui.net/docs/guides/development-guides/data-validation#manage-validationplugins
|
||||
DisableAvaloniaDataAnnotationValidation();
|
||||
|
||||
// catch all unhandled errors
|
||||
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
|
||||
@@ -94,7 +94,7 @@ public partial class App : Application
|
||||
|
||||
_host = builder.Build();
|
||||
_cancellationTokenSource = new();
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
LogStartingMode();
|
||||
@@ -119,7 +119,17 @@ public partial class App : Application
|
||||
|
||||
base.OnFrameworkInitializationCompleted();
|
||||
}
|
||||
private static void DisableAvaloniaDataAnnotationValidation()
|
||||
{
|
||||
// Get an array of plugins to remove
|
||||
var dataValidationPluginsToRemove = BindingPlugins.DataValidators.OfType<DataAnnotationsValidationPlugin>().ToArray();
|
||||
|
||||
// remove each entry found
|
||||
foreach (var plugin in dataValidationPluginsToRemove)
|
||||
{
|
||||
BindingPlugins.DataValidators.Remove(plugin);
|
||||
}
|
||||
}
|
||||
private void OnShutdownRequested(object? sender, ShutdownRequestedEventArgs e)
|
||||
=> _ = _host!.StopAsync(_cancellationTokenSource!.Token);
|
||||
|
||||
@@ -133,24 +143,27 @@ public partial class App : Application
|
||||
private void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
|
||||
=> ShowMessageBox("Unhandled Error", ((Exception)e.ExceptionObject).Message);
|
||||
|
||||
private void ShowMessageBox(string title, string message)
|
||||
private static void ShowMessageBox(string title, string message)
|
||||
{
|
||||
MessageBox.Avalonia.BaseWindows.Base.IMsBoxWindow<ButtonResult> messageBoxStandardWindow = MessageBoxManager
|
||||
.GetMessageBoxStandardWindow(title, message, ButtonEnum.Ok, Icon.Stop);
|
||||
|
||||
messageBoxStandardWindow.Show();
|
||||
}
|
||||
var box = MessageBoxManager.GetMessageBoxStandard(
|
||||
"Exception",
|
||||
text: message,
|
||||
ButtonEnum.Ok,
|
||||
Icon.Stop
|
||||
);
|
||||
_ = box.ShowAsync().GetAwaiter();
|
||||
}
|
||||
|
||||
private void LogStartingMode()
|
||||
{
|
||||
// Get the Launch mode
|
||||
bool isDevelopment = string.Equals(Environment.GetEnvironmentVariable("DOTNET_MODIFIABLE_ASSEMBLIES"), "debug",
|
||||
StringComparison.InvariantCultureIgnoreCase);
|
||||
StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
// initialize a logger & EventId
|
||||
ILogger<App> logger = _host!.Services.GetRequiredService<ILogger<App>>();
|
||||
EventId eventId = new EventId(id: 0, name: Assembly.GetEntryAssembly()!.GetName().Name);
|
||||
|
||||
|
||||
// log a test pattern for each log level
|
||||
logger.TestPattern(eventId: eventId);
|
||||
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
|
||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<None Remove="Assets\avalonia-logo.ico" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="appsettings.Development.json">
|
||||
@@ -31,4 +34,8 @@
|
||||
<ProjectReference Include="..\..\Core\MsLogger.Core\MsLogger.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<AvaloniaResource Include="Assets\avalonia-logo.ico" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -2,15 +2,24 @@ using Avalonia.Controls;
|
||||
using Avalonia.Controls.Templates;
|
||||
using AvaloniaLoggingDI.ViewModels;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace AvaloniaLoggingDI;
|
||||
|
||||
// <summary>
|
||||
/// Given a view model, returns the corresponding view if possible.
|
||||
/// </summary>
|
||||
[RequiresUnreferencedCode(
|
||||
"Default implementation of ViewLocator involves reflection which may be trimmed away.",
|
||||
Url = "https://docs.avaloniaui.net/docs/concepts/view-locator")]
|
||||
public class ViewLocator : IDataTemplate
|
||||
{
|
||||
public IControl Build(object data)
|
||||
public Control? Build(object? param)
|
||||
{
|
||||
string name = data.GetType().FullName!.Replace("ViewModel", "View");
|
||||
Type? type = Type.GetType(name);
|
||||
if (param is null)
|
||||
return null;
|
||||
|
||||
var name = param.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal);
|
||||
var type = Type.GetType(name);
|
||||
|
||||
if (type != null)
|
||||
{
|
||||
@@ -20,8 +29,8 @@ public class ViewLocator : IDataTemplate
|
||||
return new TextBlock { Text = "Not Found: " + name };
|
||||
}
|
||||
|
||||
public bool Match(object data)
|
||||
public bool Match(object? data)
|
||||
{
|
||||
return data is ViewModelBase;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
|
||||
Title="C# AVALONIA | LogViewer Control Example - Dot Net 7.0"
|
||||
Icon="avares://Avalonia.Resources/Assets/avalonia-logo.ico"
|
||||
Icon="/Assets/avalonia-logo.ico"
|
||||
WindowStartupLocation="CenterScreen" Height="634" Width="600">
|
||||
|
||||
<control:LogViewerControl DataContext="{Binding LogViewer}" />
|
||||
|
||||
Reference in New Issue
Block a user