MaterialDesignInXAML / MaterialDesignInXamlToolkit

Google's Material Design in XAML & WPF, for C# & VB.Net.
http://materialdesigninxaml.net
MIT License
15.22k stars 3.44k forks source link

StackOverFlow Exception when using DialogHost #766

Closed mynameisthing closed 3 years ago

mynameisthing commented 7 years ago

When I set the DataType for a DialogHost DataTemplate to system:String the application will crash with a Stackoverflow exception. If the DataType is set back to DateTime the issue no longer happens

I found this issue with the MainDemo.WPF project as well. I forked and made the changes in the repository below. https://github.com/akallenbach/MaterialDesignInXamlToolkit

The only Exception text I was able to get was this

System.StackOverflowException occurred
  HResult=0x800703E9
mgnslndh commented 3 years ago

Not sure this is fixable? Override the "global" DataTemplate for System.String will cause a StackOverflowException if that template tries to render a string. I guess this is to be expected. So, If you remove string rendering from that template in the demo it will work but we've essentially broken string rendering:

<!-- data template used for the dialogs example, defines a View for a ViewModel of type DateTime  -->
<DataTemplate DataType="{x:Type system:String}">
    <StackPanel Margin="16">
        <!--<TextBlock Text="England win the World Cup:"/>
        <TextBlock Margin="0 8 0 0" Text="{Binding}"/>
        <TextBlock Margin="0 8 0 0" Text="You will never see that again."/>-->
        <Button
            Margin="0 8 0 0"
            IsDefault="True"
            Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}"
            Style="{DynamicResource MaterialDesignFlatButton}"
            />
    </StackPanel>
</DataTemplate>

image

I guess you should not override the string template.

mgnslndh commented 3 years ago

The StackOverflowException is probably caused by the Button which had a string content that needed to be rendered. If you're going to override the string template you it needs to be a simple template like:

<DataTemplate DataType="{x:Type system:String}">
    <TextBlock Text="{Binding}" />
</DataTemplate>

But you probably don't want that either because all strings will be affected.

mgnslndh commented 3 years ago

I'd say we close this issue.

Keboo commented 3 years ago

Agree. Will close for now unless someone wants to come up with an alternate proposal for this