@ -1,6 +1,7 @@
using System ;
using System ;
using System.Collections.Generic ;
using System.Collections.Generic ;
using System.Linq ;
using System.Linq ;
using System.Reflection ;
using System.Threading.Tasks ;
using System.Threading.Tasks ;
using Avalonia.Automation.Peers ;
using Avalonia.Automation.Peers ;
using Avalonia.Controls.Platform ;
using Avalonia.Controls.Platform ;
@ -87,6 +88,7 @@ namespace Avalonia.Controls
/// </summary>
/// </summary>
public class Window : WindowBase , IFocusScope , ILayoutRoot
public class Window : WindowBase , IFocusScope , ILayoutRoot
{
{
private static readonly Lazy < WindowIcon ? > s_defaultIcon = new ( LoadDefaultIcon ) ;
private readonly List < ( Window child , bool isDialog ) > _ children = new List < ( Window , bool ) > ( ) ;
private readonly List < ( Window child , bool isDialog ) > _ children = new List < ( Window , bool ) > ( ) ;
private bool _ isExtendedIntoWindowDecorations ;
private bool _ isExtendedIntoWindowDecorations ;
private Thickness _ windowDecorationMargin ;
private Thickness _ windowDecorationMargin ;
@ -228,7 +230,7 @@ namespace Avalonia.Controls
this . GetObservable ( ClientSizeProperty ) . Skip ( 1 ) . Subscribe ( x = > PlatformImpl ? . Resize ( x , WindowResizeReason . Application ) ) ;
this . GetObservable ( ClientSizeProperty ) . Skip ( 1 ) . Subscribe ( x = > PlatformImpl ? . Resize ( x , WindowResizeReason . Application ) ) ;
CreatePlatformImplBinding ( TitleProperty , title = > PlatformImpl ! . SetTitle ( title ) ) ;
CreatePlatformImplBinding ( TitleProperty , title = > PlatformImpl ! . SetTitle ( title ) ) ;
CreatePlatformImplBinding ( IconProperty , icon = > PlatformImpl ! . SetIcon ( icon ? . PlatformImpl ) ) ;
CreatePlatformImplBinding ( IconProperty , icon = > PlatformImpl ! . SetIcon ( ( icon ? ? s_defaultIcon . Value ) ? . PlatformImpl ) ) ;
CreatePlatformImplBinding ( CanResizeProperty , canResize = > PlatformImpl ! . CanResize ( canResize ) ) ;
CreatePlatformImplBinding ( CanResizeProperty , canResize = > PlatformImpl ! . CanResize ( canResize ) ) ;
CreatePlatformImplBinding ( ShowInTaskbarProperty , show = > PlatformImpl ! . ShowTaskbarIcon ( show ) ) ;
CreatePlatformImplBinding ( ShowInTaskbarProperty , show = > PlatformImpl ! . ShowTaskbarIcon ( show ) ) ;
@ -1100,5 +1102,19 @@ namespace Avalonia.Controls
{
{
return new WindowAutomationPeer ( this ) ;
return new WindowAutomationPeer ( this ) ;
}
}
private static WindowIcon ? LoadDefaultIcon ( )
{
// Use AvaloniaLocator instead of static AssetLoader, so it won't fail on Unit Tests without any asset loader.
if ( AvaloniaLocator . Current . GetService < IAssetLoader > ( ) is { } assetLoader
& & Assembly . GetEntryAssembly ( ) ? . GetName ( ) ? . Name is { } assemblyName
& & Uri . TryCreate ( $"avares://{assemblyName}/!__AvaloniaDefaultWindowIcon" , UriKind . Absolute , out var path )
& & assetLoader . Exists ( path ) )
{
using var stream = assetLoader . Open ( path ) ;
return new WindowIcon ( stream ) ;
}
return null ;
}
}
}
}
}