question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error template disappears from Cell after changing menu in HamburgerMenu

See original GitHub issue

Describe the bug

Hello I have a WPF application where I use Prism and Mahapps. I have a DataGrid with model which implements INotifyDataErrorInfo Interface, after loading data to grid I see some cells with red border (the value is invalid there) but if go to another MenuItem in HamburgerMenu and then I back to the first MenuItem the red border are disappeared. I have tried using AdornerDecorator but it didn’t help. Then I have tried custom styles, and data temples for ErrorTemplate but it didn’t help too. But If I add following code, it works.

        <DataGrid.Resources>
            <Style  TargetType="{x:Type DataGridCell}" BasedOn="{StaticResource MahApps.Styles.DataGridCell}" >
                <Style.Triggers>
                    <MultiTrigger>
                        <MultiTrigger.Conditions>


                        </MultiTrigger.Conditions>


                    </MultiTrigger>
                </Style.Triggers>
            </Style>
        </DataGrid.Resources>

I have no idea why it behaves like that.

Steps to reproduce

  1. Make model which implements INotifyDataErrorInfo .
  2. Load some data to DataGrid, cells with incorrect data (validated by functions from INotifyDataErrorInfo ) should have red borders now.
  3. Change View via HamburgerMenu
  4. Back to View with Grid. Now red borders disappears.
  5. Add the code from description. Now it should work.

Here is the View with DataGrid

<UserControl x:Class="PrismJPKEditor.Modules.JPK.Views.Declaration"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:prism="http://prismlibrary.com/"             
             prism:ViewModelLocator.AutoWireViewModel="True">

    
    
    <DataGrid GridLinesVisibility="All" ItemsSource="{Binding SessionContext.JPKDataSource.Declaration.Declarations}" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" >

        <DataGrid.Resources>
            <Style  TargetType="{x:Type DataGridCell}" BasedOn="{StaticResource MahApps.Styles.DataGridCell}" >
                <Style.Triggers>
                    <MultiTrigger>
                        <MultiTrigger.Conditions>


                        </MultiTrigger.Conditions>


                    </MultiTrigger>
                </Style.Triggers>
            </Style>
        </DataGrid.Resources>


        <DataGrid.Columns>
            <DataGridTextColumn IsReadOnly="True" Width="auto" Header="Nazwa pola" Binding="{Binding FieldName}"/>
            <DataGridTextColumn IsReadOnly="True" Width="auto" Header="Opis pola" Binding="{Binding Description}"/>
            <DataGridTextColumn   IsReadOnly="False" Width="auto" Header="Wartość pola" Binding="{Binding GridValue, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"/>
        </DataGrid.Columns>
    </DataGrid>
</UserControl>

Expected behavior

The error template should stays after changing view via HamburgerMenu.

Actual behavior

The error template disappears.

Environment

MahApps.Metro version: v2.0.0
Windows build number: Win10 1909 [Version 10.0.18363.836]
Visual Studio: 2019 16.6.0
Target Framework: .Net Core 3.1 (v4.5.2, v4.7.2)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
punker76commented, Jan 5, 2021

@GWawrzeniecki The default cell style is set to the CellStyle of the DataGrid. So if you define a new global style in your App.xaml this style will not use (or only once). You can prevent this if you give your style a key and use this explicitly on your DataGrid.

<Style x:Key="SpecialCellStyle" TargetType="{x:Type DataGridCell}" BasedOn="{StaticResource MahApps.Styles.DataGridCell}" >
    <Style.Triggers>
        <MultiTrigger>
            <MultiTrigger.Conditions>
            </MultiTrigger.Conditions>
        </MultiTrigger>
    </Style.Triggers>
</Style>
<DataGrid Style="{StaticResource SpecialCellStyle}" ... />

If you use this style always then you can set this to a global DataGrid style.

<Style TargetType="{x:Type DataGrid}" BasedOn="{StaticResource {x:Type DataGrid}}">
  <Setter Property="CellStyle" Value="{StaticResource SpecialCellStyle}" />
</Style>
0reactions
timuniecommented, Jan 14, 2021

Hi @GWawrzeniecki

I made a simple test without prism and it works. https://github.com/GWawrzeniecki/JPK/pull/1 Maybe it has to do with PRISM?

Happy coding Tim

Read more comments on GitHub >

github_iconTop Results From Across the Web

After clicking mobile menu and changing landscape ...
I have done a hamburger menu for a mobile phone and applied @media queries for different screen sizes and orientations. The problem:.
Read more >
Mobile Menu Disappears When Touched - Support
Hi David, I checked your website on mobile and found the Hamburger menu is showing, but while clicked into the menu it suddenly...
Read more >
Hamburger menu button missing on mobile device
I have tried switching to several other themes and it's exactly the same. The menu is selected as the primary menu. On the...
Read more >
Mobile Navigation Hamburger Menu Going Blank
My site displays fine on desktop but frustratingly the hamburger dropdown menu flashes to white/blank when clicked on mobile.
Read more >
Missing hamburger menu in mobile format
Hi. For some reason the menu has disappeared in mobile format It was working last time I checked? Currently building the site at ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found