Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 2 additions & 19 deletions dotnet-avalonia/App.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Data.Core;
using Avalonia.Data.Core.Plugins;
using System.Linq;
using Avalonia.Markup.Xaml;
using dnd.Services;
using dnd.ViewModels;
Expand All @@ -27,9 +24,8 @@ public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
// Avoid duplicate validations from both Avalonia and the CommunityToolkit.
// More info: https://docs.avaloniaui.net/docs/guides/development-guides/data-validation#manage-validationplugins
DisableAvaloniaDataAnnotationValidation();
// DataAnnotations validation is opt-in since Avalonia 12 (AppBuilder.WithDataAnnotationsValidation),
// so it no longer has to be removed to avoid duplicate validation with the CommunityToolkit.
desktop.MainWindow = new MainWindow
{
DataContext = new MainWindowViewModel(),
Expand All @@ -42,17 +38,4 @@ public override void OnFrameworkInitializationCompleted()

base.OnFrameworkInitializationCompleted();
}

private 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);
}
}
}
4 changes: 2 additions & 2 deletions dotnet-avalonia/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public MainWindow()

private void DragOver(object? sender, DragEventArgs e)
{
var hasFiles = e.Data.Contains(DataFormats.Files);
var hasFiles = e.DataTransfer.Contains(DataFormat.File);
e.DragEffects = hasFiles ? DragDropEffects.Copy : DragDropEffects.None;
SetDragOver(hasFiles);
}
Expand All @@ -31,7 +31,7 @@ private void DragLeave(object? sender, DragEventArgs e)
private void Drop(object? sender, DragEventArgs e)
{
SetDragOver(false);
var files = e.Data.GetFiles();
var files = e.DataTransfer.TryGetFiles();
if (files != null && DataContext is MainWindowViewModel vm)
vm.DropCommand.Execute(files);
}
Expand Down
17 changes: 6 additions & 11 deletions dotnet-avalonia/dnd.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Avalonia" Version="11.2.1"/>
<PackageReference Include="Avalonia.Desktop" Version="11.2.1"/>
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.2.1"/>
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.2.1"/>
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Include="Avalonia.Diagnostics" Version="11.2.1">
<IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
</PackageReference>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Avalonia" Version="12.1.4"/>
<PackageReference Include="Avalonia.Desktop" Version="12.1.4"/>
<PackageReference Include="Avalonia.Themes.Fluent" Version="12.1.4"/>
<PackageReference Include="Avalonia.Fonts.Inter" Version="12.1.4"/>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.2"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.13" />
</ItemGroup>
</Project>
Loading