Skip to content

Commit

Permalink
updated deps, fixed bug when adding tab
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKoell committed Sep 19, 2024
1 parent 48e86fd commit dadb589
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<RootNamespace>RoyalApps.Community.Avalonia.Common</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Avalonia" Version="11.0.0-rc2.2" />
<PackageReference Include="Avalonia" Version="11.1.3" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0-windows</TargetFramework>
<RuntimeIdentifiers>win10-x64;win10-arm64</RuntimeIdentifiers>
<TargetFramework>net8.0-windows</TargetFramework>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<Platforms>x64;ARM64</Platforms>
<Configurations>Debug;Release</Configurations>
<UseWindowsForms>true</UseWindowsForms>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@
x:Class="InteropDemo.App">
<Application.Styles>
<FluentTheme />

<Style Selector="Window[ActualTransparencyLevel=Mica]">
<Setter Property="Background" Value="Transparent" />
</Style>

</Application.Styles>
</Application>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace InteropDemo;
public class App : Application
{
public static MainViewModel MainViewModel;

static App()
{
MainViewModel = new MainViewModel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net7.0-windows</TargetFramework>
<RuntimeIdentifiers>win10-x64;win10-arm64</RuntimeIdentifiers>
<TargetFramework>net8.0-windows</TargetFramework>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<Platforms>x64;ARM64</Platforms>
<Configurations>Debug;Release</Configurations>
<UseWindowsForms>true</UseWindowsForms>
Expand All @@ -25,14 +25,14 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Avalonia" Version="11.0.0-rc2.2" />
<PackageReference Include="Avalonia.Desktop" Version="11.0.0-rc2.2" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.0-rc2.2" />
<PackageReference Include="Avalonia" Version="11.1.3" />
<PackageReference Include="Avalonia.Desktop" Version="11.1.3" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.1.3" />

<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.0-rc2.2" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.0" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.18-beta">
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.3" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.2" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.106">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="InteropDemo.MainView"
x:CompileBindings="True"
x:DataType="viewModels:MainViewModel"
>
x:DataType="viewModels:MainViewModel">
<Grid RowDefinitions="Auto,*" >

<Menu Grid.Row="0">
<MenuItem Header="_Tabs">
<MenuItem Header="_Add" Command="{Binding Add}" />
<MenuItem Header="_Close" Command="{Binding Remove}" />
</MenuItem>
</Menu>
<Grid ColumnDefinitions="Auto, *">
<Menu Grid.Row="0">
<MenuItem Header="_Tabs">
<MenuItem Header="_Add" Command="{Binding AddTabCommand}" />
<MenuItem Header="_Close" Command="{Binding RemoveTabCommand}" />
</MenuItem>
<MenuItem Header="_Appearance">
<MenuItem Header="_Toggle Theme" Command="{Binding ToggleThemeCommand}" />
<MenuItem Header="_Toggle Mica" Command="{Binding ToggleMicaCommand}" />
</MenuItem>
</Menu>
<Border Grid.Column="1" Height="30" IsHitTestVisible="False" />
</Grid>

<TabControl Name="TabControl" ItemsSource="{Binding Tabs}" SelectedItem="{Binding SelectedTab}" Grid.Row="1" >
<TabControl.ItemTemplate>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,33 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:interopDemo="clr-namespace:InteropDemo"
xmlns:windows="clr-namespace:RoyalApps.Community.Avalonia.Windows;assembly=RoyalApps.Community.Avalonia.Windows"
xmlns:viewModels="clr-namespace:InteropDemo.ViewModels"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
UseLayoutRounding="True" RenderOptions.BitmapInterpolationMode="HighQuality"
x:Class="InteropDemo.MainWindow"
TransparencyLevelHint="AcrylicBlur"
Title="Interop Demo"
ExtendClientAreaToDecorationsHint="False"
ExtendClientAreaChromeHints="PreferSystemChrome">
<Panel>
<ExperimentalAcrylicBorder IsHitTestVisible="False">
<ExperimentalAcrylicBorder.Material>
<ExperimentalAcrylicMaterial BackgroundSource="Digger"
TintColor="{DynamicResource SystemAltHighColor}"
TintOpacity="1"
FallbackColor="{DynamicResource AcrylicFallbackColor}"
MaterialOpacity="0.55" />
</ExperimentalAcrylicBorder.Material>
</ExperimentalAcrylicBorder>
<Panel>
<Panel>
<interopDemo:MainView />
</Panel>
</Panel>
</Panel>
TransparencyLevelHint="{Binding Transparency}"
ExtendClientAreaToDecorationsHint="True"
ExtendClientAreaChromeHints="PreferSystemChrome"
x:Class="InteropDemo.MainWindow"
x:DataType="viewModels:MainViewModel">

<interopDemo:MainView />

<!-- <Panel> -->
<!-- <ExperimentalAcrylicBorder IsHitTestVisible="False"> -->
<!-- <ExperimentalAcrylicBorder.Material> -->
<!-- <ExperimentalAcrylicMaterial BackgroundSource="Digger" -->
<!-- TintColor="{DynamicResource SystemAltHighColor}" -->
<!-- TintOpacity="1" -->
<!-- FallbackColor="{DynamicResource AcrylicFallbackColor}" -->
<!-- MaterialOpacity="0.55" /> -->
<!-- </ExperimentalAcrylicBorder.Material> -->
<!-- </ExperimentalAcrylicBorder> -->
<!-- <Panel> -->
<!-- <Panel> -->
<!-- </Panel> -->
<!-- </Panel> -->
<!-- </Panel> -->

</Window>
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using Avalonia.Controls;
using Avalonia.Markup.Xaml;

namespace InteropDemo;

public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
AvaloniaXamlLoader.Load(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public static AppBuilder BuildAvaloniaApp()
.UsePlatformDetect()
.With(new Win32PlatformOptions
{
CompositionMode = new [] {Win32CompositionMode.WinUIComposition, Win32CompositionMode.LowLatencyDxgiSwapChain, Win32CompositionMode.RedirectionSurface},
OverlayPopups = true,
//CompositionMode = new [] {Win32CompositionMode.RedirectionSurface},
})
.LogToTrace();
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Styling;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;

Expand All @@ -8,23 +13,45 @@ public partial class MainViewModel : ViewModelBase
{
private int _counter = 1;
[ObservableProperty] private TabViewModel? _selectedTab;
[ObservableProperty] private IReadOnlyList<WindowTransparencyLevel> _transparency = [WindowTransparencyLevel.Mica, WindowTransparencyLevel.Transparent
];
public ObservableCollection<TabViewModel> Tabs { get; set; } = new();
[RelayCommand] public void Add() => AddTab(new TestViewModel());
[RelayCommand] public void Remove() => RemoveTab(SelectedTab);

private void AddTab(TabViewModel tab)
[RelayCommand]
private void AddTab(TabViewModel? tab)
{
tab ??= new TestViewModel();
tab.Caption += $" {_counter++}";
Tabs.Add(tab);
SelectedTab = tab;
}

public void RemoveTab(TabViewModel? tab)
[RelayCommand]
private void RemoveTab(TabViewModel? tab)
{
if (tab is null)
return;

tab.RaiseTabClosing();
Tabs.Remove(tab);
}

[RelayCommand]
private void ToggleTheme()
{
if (Application.Current is null)
return;

Application.Current.RequestedThemeVariant = Application.Current.ActualThemeVariant == ThemeVariant.Light
? ThemeVariant.Dark
: ThemeVariant.Light;
}

[RelayCommand]
private void ToggleMica()
{
Transparency = Transparency.Contains(WindowTransparencyLevel.Mica)
? []
: new[] { WindowTransparencyLevel.Mica };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public partial class TabViewModel : ViewModelBase, IDisposeWinFormsControl

public event EventHandler<WinFormsDisposeEventArgs>? DisposeWinFormsControl;

[RelayCommand] public void Close() => App.MainViewModel.RemoveTab(this);
[RelayCommand] public void Close() => App.MainViewModel.RemoveTabCommand.Execute(this);

public void RaiseTabClosing()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
<PackageIcon>RoyalApps_1024.png</PackageIcon>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RootNamespace>RoyalApps.Community.Avalonia.Windows</RootNamespace>
<Version>1.0.3</Version>
<Version>1.1.0-beta1</Version>
</PropertyGroup>

<PropertyGroup>
<TargetFramework>net7.0-windows</TargetFramework>
<RuntimeIdentifiers>win10-x64;win10-arm64</RuntimeIdentifiers>
<TargetFramework>net8.0-windows</TargetFramework>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<Configurations>Debug;Release</Configurations>
<Platforms>x64;ARM64</Platforms>
<UseWindowsForms>true</UseWindowsForms>
Expand All @@ -29,8 +29,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Avalonia" Version="11.0.0-rc2.2" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.2-beta">
<PackageReference Include="Avalonia" Version="11.1.3" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.106">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down

0 comments on commit dadb589

Please sign in to comment.