dotnet / wpf

WPF is a .NET Core UI framework for building Windows desktop applications.
MIT License
7.08k stars 1.17k forks source link

RibbonButton throws an exception on .Net Core #397

Closed jherby2k closed 5 years ago

jherby2k commented 5 years ago

Can't add RibbonButtons to a Ribbon control - it throws an exception.

Actual behavior:

System.Windows.Markup.XamlParseException
  HResult=0x80131501
  Message=Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' threw an exception.
  Source=PresentationFramework
  StackTrace:
   at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)

Inner Exception 1:
ArgumentException: 13px is not a valid value for Double.
Parameter name: value

Inner Exception 2:
FormatException: Input string was not in a correct format.

Expected behavior:

A Copy button is rendered

Minimal repro:

<Window x:Class="TestApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
        <Ribbon>
            <RibbonTab>
                <RibbonGroup>
                    <RibbonButton/>
                </RibbonGroup>
            </RibbonTab>
        </Ribbon>
</Window>
jherby2k commented 5 years ago

Tested with preview4 from https://dotnetcli.blob.core.windows.net/dotnet/Sdk/master/dotnet-sdk-latest-win-x64.exe. Still broke.

FTWinston commented 5 years ago

I'm seeing this same error, am just putting in regular buttons instead of RibbonButtons as an ugly workaround for now.

jbe2277 commented 5 years ago

I see the same issue:

slozier commented 5 years ago

I also hit this issue when trying to run my app with .NET Core 3.0. It occurs with other flavors of RibbonButtons as well (e.g. RibbonToggleButton, RibbonSplitButton, etc.). Might be related to <RibbonTwoLineText LineHeight="13px" ...> in Generic.xaml?

stevenbrix commented 5 years ago

Thanks everyone for commenting and letting us know about this issue! I'll investigate and see what i can find

stevenbrix commented 5 years ago

It looks like this is a PBT issue and we we are not using the proper converter. We are using a System.ComponentModel.DoubleConverter when we should be using System.Windows.LengthConverter

ryalanms commented 5 years ago

If this is a PBT issue, please assign to me. Thanks.

ryalanms commented 5 years ago

The markup in the minimal repro now builds and runs with the most recent SDK.

<Window x:Class="ribtest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:ribbon="clr-namespace:System.Windows.Controls.Ribbon;assembly=System.Windows.Controls.Ribbon">
    <ribbon:Ribbon>
        <ribbon:RibbonTab>
            <ribbon:RibbonGroup>
                <ribbon:RibbonButton/>
            </ribbon:RibbonGroup>
        </ribbon:RibbonTab>
    </ribbon:Ribbon>
</Window
ryalanms commented 5 years ago

I see the same issue:

System.Windows.Markup.XamlParseException: Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' threw an exception. ---> System.ArgumentException: 13px is not a valid value for Double.
Parameter name: value ---> System.FormatException: Input string was not in a correct format.
   at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, TypeCode type)
   at System.Double.Parse(String s, NumberStyles style, IFormatProvider provider)
   at System.ComponentModel.DoubleConverter.FromString(String value, NumberFormatInfo formatInfo)
   at System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
   --- End of inner exception stack trace ---
   at System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
   at System.Windows.Baml2006.TypeConverterMarkupExtension.ProvideValue(IServiceProvider serviceProvider)
   at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CallProvideValue(MarkupExtension me, IServiceProvider serviceProvider)
   --- End of inner exception stack trace ---
   at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
   at System.Windows.Markup.XamlReader.RewrapException(Exception e, Uri baseUri)
   at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter)
   at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlObjectWriter objectWriter)

@jbe2277: Are you still seeing the error when targeting .NET core 3.0? The Writer.Presentation sample project is targeting 4.6.1. Thanks.

jbe2277 commented 5 years ago

@ryalanms: I don't see this issue anymore with the latest .NET Core 3.0 version.

Please use the netcoreapp3.0 branch instead of master. Within this branch I have migrated the whole Win Application Framework (WAF) to .NET Core 3.

ryalanms commented 5 years ago

Thanks, @jbe2277. I will use that to test future changes.