cimbalino/Cimbalino-Toolkit

MultiBind on Textblock Text field fails in UWP

Closed this issue · 5 comments

Noticed that a multibind will fail consistently for me when bound in UWP to the Text field of a TextBlock, noting: Unhandled exception at 0x7757DF95 (combase.dll).

Sample code:

                <TextBlock Foreground="AntiqueWhite" FontSize="12" FontWeight="Bold" Text="13.41">
                        <Interactivity:Interaction.Behaviors>
                            <cimba:MultiBindingBehavior Converter="{StaticResource IntToValConverter}" 
                                                        PropertyName="Text"  >
                                <cimba:MultiBindingItem Value="{Binding StepValue}"/>
                            </cimba:MultiBindingBehavior>
                        </Interactivity:Interaction.Behaviors>
                </TextBlock>

And the Converter:

    public class IntToValConverter : MultiValueConverterBase
    {
        public override object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (null == values[0]) return "haha";
            return "hoho";
        }
        public override object[] ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

Does this happen if you run the app on Debug or only on Release mode?

So this happens only in Release, and leads me to think there's some kind of null-error behind the scenes in what the bind's providing to the Text field at runtime. Least that's my guess.

Given it only happens on Release mode, we can safely assume this is due to .NET Native optimizations... I'm not sure I'll be able to fix this on my side, but I think I have a solution for this specific case!

Add this to your app Default.rd.xml file, rebuild and try again:

<Type Name="Windows.UI.Xaml.Controls.TextBlock">
  <Property Name="Text" Serialize="Required"/>
</Type>

That is indeed a functional work around. I'll have to do some reading to see how/why it works. Since as you said it's more of a .NET optimization issue, I suppose this issue can be closed?

Yep, I don't think I'll be able to do "magic" stuff over this one, but I'm hoping Microsoft might! ;)

In the meantime, here's something to read on the subject if you want to!