-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WinAppSDK crash on startup when using most Material styles #361
Comments
This is a result of using the FilledButtonStyle on a Button |
The error is this:
And it seems to be happening with any control that has this in the template: Visibility="{Binding Path=(um:ControlExtensions.Icon), RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource MaterialNullToCollapsedConverter}, FallbackValue=Collapsed, TargetNullValue=Collapsed}" It looks like there's been a change in winui surrounding this? Can no longer have the converter return a string of "Visible" or "Collapsed", if I instead make it return a Visiblity enum value or create Visibility StaticResources and set those as the properties of the converter then it works <Visibility x:Key="VisibleVal">Visible</Visibility>
<Visibility x:Key="CollapsedVal">Collapsed</Visibility>
<local:MyConverter x:Key="MaterialNullToCollapsedConverter"
NotNullValue="{StaticResource VisibleVal}"
NullValue="{StaticResource CollapsedVal}" /> |
would it work if you used string literals "True" "False" directly on the converter's properties? |
Using True/False doesn't cause a crash but it also doesn't work and just stays as Visible no matter what MyProp is. So basically <Page x:Class="MaterialTestApp.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MaterialTestApp"
xmlns:um="using:Uno.Material"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:maui="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:not_maui="http://notmaui"
mc:Ignorable="d not_maui"
Background="{ThemeResource BackgroundBrush}">
<Page.Resources>
<Visibility x:Key="VisibleVal">Visible</Visibility>
<Visibility x:Key="CollapsedVal">Collapsed</Visibility>
<local:MyConverter x:Key="MyConverter1"
FalseValue="{StaticResource CollapsedVal}"
TrueValue="{StaticResource VisibleVal}" />
<local:MyConverter x:Key="MyConverter2"
FalseValue="False"
TrueValue="True" />
<local:MyConverter x:Key="MyConverter3"
FalseValue="Collapsed"
TrueValue="Visible" />
</Page.Resources>
<StackPanel HorizontalAlignment="Center"
VerticalAlignment="Center">
<Button Content="Toggle MyProp"
Click="Button_Click" />
<!--Works-->
<CheckBox Content="Converter 1" Visibility="{Binding MyProp, Converter={StaticResource MyConverter1}}" />
<!--Compiles but doesn't toggle Visibility-->
<CheckBox Content="Converter 2" Visibility="{Binding MyProp, Converter={StaticResource MyConverter2}}" />
<!--Crashes-->
<CheckBox Content="Converter 3" Visibility="{Binding MyProp, Converter={StaticResource MyConverter3}}" />
</StackPanel>
</Page> |
I'm curious why this started happening but since this looks like a WinAppSDK thing, I guess we should just create some sort of specific NullToVisibilityConverter and use that instead? |
After discussion, we will refactor the Uno.Themes repo to find any places where we are using a Converter with parameters for the Visiblity and instead use a new converter that is specific for Visibility that returns a strongly-typed |
only for Uno.Material?? or we need to do the replacement on the Uno.Cupertino styles?? @kazo0 |
@Arieldelossantos on second thought, could you maybe spend some time trying to investigate why this crash is happening on Windows? I can't seem to get it to crash on Chefs or any other app that I update to the latest WinAppSdk version. You should be able to get it to crash by just doing |
@Arieldelossantos Can you try creating a new WinAppSDK app from Visual Studio (not an Uno app, an actual Windows app) and attempt to reproduce this behavior in both an Unpackaged and Packaged version of a Windows app? |
@Arieldelossantos In order to test, create an native Windows app and use this converter public class MyConverter : IValueConverter
{
public object FalseValue { get; set; }
public object TrueValue { get; set; }
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value is bool b)
{
return b ? TrueValue : FalseValue;
}
return FalseValue;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
} With your XAML looking similar to: <Page x:Class="UnoApp73.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UnoApp73"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Page.Resources>
<local:MyConverter x:Key="MyConverter"
FalseValue="Collapsed"
TrueValue="Visible" />
</Page.Resources>
<StackPanel HorizontalAlignment="Center"
VerticalAlignment="Center">
<CheckBox Content="Toggle"
x:Name="MyCheckBox" />
<Button Content="Test"
Visibility="{Binding ElementName=MyCheckBox, Path=IsChecked, Converter={StaticResource MyConverter}}" />
</StackPanel>
</Page> And see if it crashes |
@Arieldelossantos Actually, can you try with latest templates |
it's still crashing for me @kazo0 :/ |
Related issue : microsoft/microsoft-ui-xaml#9021 |
Closing this as it's been resolved by removing trimming |
Installing latest dev templates with
dotnet new install uno.templates::5.0.0-dev.486
and runningdotnet new unoapp -o MyTestApp
results in a crash on startup when running the Windows head:With latest VS Stable and VS Preview
App starts fine if I use
dotnet new unoapp -preset=blank -o MyTestApp
The text was updated successfully, but these errors were encountered: