Simnico99 / MicaWPF

This is a library to make Mica available in WPF.
MIT License
210 stars 11 forks source link

[Bug] WinRT issues on Windows 11 version 22000 #69

Closed julianpoelmann closed 1 year ago

julianpoelmann commented 1 year ago

ive followed this step by step. had issues with the .net target framework but they seem to have dissapeared but now i have a missing file error.

System.TypeInitializationException
  HResult=0x80131534
  Message=The type initializer for 'MicaWPF.Controls.MicaWindow' threw an exception.
  Source=MicaWPF
  StackTrace:
   at MicaWPF.Controls.MicaWindow..ctor()
   at KoalaBound.MainWindow..ctor() in E:\VisualStudioProjects\KoalaBound\MainWindow.xaml.cs:line 24
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)

  This exception was originally thrown at this call stack:
    [External Code]

Inner Exception 1:
TypeInitializationException: The type initializer for 'MicaWPF.Services.AccentColorService' threw an exception.

Inner Exception 2:
FileNotFoundException: Could not load file or assembly 'WinRT.Runtime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=99ea127f02d97709'. Het systeem kan het opgegeven bestand niet vinden.

I expected it to work

image

Windows 11 11 Pro N for Workstations Build 22000.1696 .Net 6.0

Simnico99 commented 1 year ago

What is in your app.xaml?

julianpoelmann commented 1 year ago
<Application x:Class="KoalaBound.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:KoalaBound"
             xmlns:mica="clr-namespace:MicaWPF.Styles;assembly=MicaWPF"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <mica:ThemeDictionary Theme="Auto" />
                <!-- And Here (You can change to Light or Dark here) -->
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>
Simnico99 commented 1 year ago

I will change the docs to reflect this since it is in the getting started with controls but is now nescessary since starting the AccentColorService from ThemeService was causing issues at startup.

Add the :

<Application x:Class="KoalaBound.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:KoalaBound"
             xmlns:mica="clr-namespace:MicaWPF.Styles;assembly=MicaWPF"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <mica:ThemeDictionary Theme="Auto" />
                <!-- And Here (You can change to Light or Dark here) -->
                 <mica:ControlsDictionary /> <!-- Here -->
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>
Simnico99 commented 1 year ago

Fixed the documentation to reflect the change. Changed the README and the Getting started section of the wiki.

julianpoelmann commented 1 year ago

Eyy nice, I'll try this after work. Also thanks for the quick replies!

julianpoelmann commented 1 year ago

same exact error. in the screenshot it doesnt show the winrt error its giving but it does in the text log i sent

Simnico99 commented 1 year ago

Do you use Net5.0+?

If yes your csproj file needs to be modified and those lines needs to be modified/added

<TargetFramework>net7.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>7.0</TargetPlatformMinVersion>

Because it does use winrt for communication with UWP for color accuracy.

julianpoelmann commented 1 year ago

im using net6 and did it like this

<TargetFramework>net6.0-windows10.0.22621.0</TargetFramework>
      <TargetPlatformMinVersion>6.0</TargetPlatformMinVersion>

im on 11, the build number in your message instantly results in an error. the one i put in is from a list it showed me with the ones that should work.

i tried making it 7 but it returns the same error

julianpoelmann commented 1 year ago

i tried it in a fresh net7 project and the same issue appears

Simnico99 commented 1 year ago

Zip and send the project I will test on my side

julianpoelmann commented 1 year ago

alrighty. do you prefer gdrive or megasync?

Simnico99 commented 1 year ago

Gdrive, but any is fine.

julianpoelmann commented 1 year ago

https://drive.google.com/file/d/1D10OQwss-JGa-fGc21gvroBQb0Qow0Pc/view?usp=sharing

Simnico99 commented 1 year ago

https://drive.google.com/file/d/1D10OQwss-JGa-fGc21gvroBQb0Qow0Pc/view?usp=sharing

The file you sent I modified the csproj to these then it runs fine image image image

Here is my windows build: image

Simnico99 commented 1 year ago

I would recommend upgrading Windows to 22H2 and try again as Windows 22000 the original version I was using an undocumented API they might have retired it in the lastest versions.

I will spin up a VM of version 22000 and try.

julianpoelmann commented 1 year ago

i cannot upgrade to 22h2 due to compatibility issues with the windows 10 explorer (im using a tweak that lets me have the windows 10 taskbar and explorer on windows 11) .

also im currently building on netcore3.1 and that works. might have to apply this tho as im trying to integrate depotdownloader which requires net6+.

also i have another question, how can i make a button opaque? i tried to find a checkbox for it or chaning the brushes but it remains image

Simnico99 commented 1 year ago

i cannot upgrade to 22h2 due to compatibility issues with the windows 10 explorer (im using a tweak that lets me have the windows 10 taskbar and explorer on windows 11) .

also im currently building on netcore3.1 and that works. might have to apply this tho as im trying to integrate depotdownloader which requires net6+.

also i have another question, how can i make a button opaque? i tried to find a checkbox for it or chaning the brushes but it remains image

I will never understand the peoples upgrading to 11 that want things to look like 10 (Shrug). For the button if you want to use the Accent colored one you can use this style: MicaWPF.Styles.AccentedButton

To customize the color you can change the color in the ThemeService (It will use the accent color of Windows by default): https://github.com/Simnico99/MicaWPF/wiki/Change-Theme-or-Accent-color#updateaccentscolor

And I think I know why .Net6 + doesn't work because of a dll in C++ linked with WinRT that I use, .Net Framework and netcore doesn't need it as it was integrated to it.

julianpoelmann commented 1 year ago

i prefer the style of the older bar and its a lil more compact.

im having trouble applying the button style (im very new to wpf, im used to winforms). also i had the same issue with net 7, it is the winrt issue. id prefer not to use net framework as it kinda always messes up the way i update my applications

Simnico99 commented 1 year ago

i prefer the style of the older bar and its a lil more compact.

im having trouble applying the button style (im very new to wpf, im used to winforms). also i had the same issue with net 7, it is the winrt issue. id prefer not to use net framework as it kinda always messes up the way i update my applications

I will fire up my VM this week end and take a look I wrote net6+ (Because + means Net7 and Net8 and future ones)

Here is sample code for the button:

        <controls:Button Style="{StaticResource MicaWPF.Styles.AccentedButton}">
            I am an accented button
        </controls:Button>
julianpoelmann commented 1 year ago

image

Simnico99 commented 1 year ago

image

Try changing staticressource to DynamicResource

julianpoelmann commented 1 year ago

no difference

Simnico99 commented 1 year ago

Ah wait It might show an error in the IDE but if you run it it should work fine

julianpoelmann commented 1 year ago

your right but it does show up strangely image

Simnico99 commented 1 year ago

your right but it does show up strangely image

Ah add a height

        <controls:Button Style="{StaticResource MicaWPF.Styles.AccentedButton}" Height="45">
            I am an accented button
        </controls:Button>
julianpoelmann commented 1 year ago

it already has height but i do notice it lacks width. i added width but it still looks the same.

also i do not see the usual option to suppress the error the ide is giving about the style

Simnico99 commented 1 year ago

it already has height but i do notice it lacks width. i added width but it still looks the same.

also i do not see the usual option to suppress the error the ide is giving about the style

Add a slight margin like (Adjust as needed)

        <controls:Button Style="{StaticResource MicaWPF.Styles.AccentedButton}" Height="45" margin="2">
            I am an accented button
        </controls:Button>

Also for the IDE sometimes it needs a restart to work properly I know Visual studio 2019/2022 is a bit finicky with WPF and sometimes fucks up big time.

julianpoelmann commented 1 year ago

it also already has a margin, the margin keeps it in its place-

also oof ill restart it then

Simnico99 commented 1 year ago

Humm weird my exemple code works well on my side

<controls:MicaWindow
    x:Class="MicaWPF.Test.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="clr-namespace:MicaWPF.Controls;assembly=MicaWPF"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    Width="800"
    Height="450"
    d:Background="{DynamicResource MicaWPF.Brushes.ApplicationBackground}"
    TitleBarType="WinUI"
    mc:Ignorable="d">
    <Grid >
        <controls:Button  Style="{StaticResource MicaWPF.Styles.AccentedButton}" VerticalAlignment="Top" Height="45" Margin="5" >
            I am an accented button
        </controls:Button>
    </Grid>

</controls:MicaWindow>

image

Normally it looks like yours if the border is actually cut off by something that is why I asked for the margin

julianpoelmann commented 1 year ago

this is basically my buttons

<controls:Button x:Name="StartGameButton" Style="{DynamicResource MicaWPF.Styles.AccentedButton}" Content="Start" Margin="194,327,460,0" VerticalAlignment="Top" Height="50" FontFamily="Starbound Font" MouseEnter="StartGameButton_MouseEnter" Click="StartGameButton_Click" ClipToBounds="True" IsDefault="True"/>
Simnico99 commented 1 year ago

ClipToBounds="True" is removing the border

julianpoelmann commented 1 year ago

that fixed it, i had it enabled because for some reason at runtime the font i use loses like an entire line of pixels, i thought that cliptobounds would fix it

julianpoelmann commented 1 year ago

also the xaml designer crashes constantly when loading properties of mainly the grid and the window. sometimes it works but now its stuck crashing all the time

Simnico99 commented 1 year ago

Fixed with version 6.0.0 Use the MicaWPF.Lite package.