wpfuser-controls

XamlParseException :: Cannot find resource named 'DefaultStyle`


I have customized a togglebutton to use in a control box. But then it threw this exception when i hovered over it:

System.Windows.Markup.XamlParseException: ''Provide value on 'System.Windows.Markup.StaticResourceHolder' threw an exception.'

Inner exception:

'Cannot find resource named 'DefaultStyle'. Resource names are case sensitive.

which is kind of odd since nothing is either named or using the name DefaultStyle in my entire project!

After a little digging i noticed that the error comes delayed and so i remembered that this time i added a tooltip which seems to be causing the problem but i can't figure out why!

Here's the XAML:

<Style x:Key="ToggleClose" TargetType="{x:Type ToggleButton}">
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="SnapsToDevicePixels" Value="True" />

    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ToggleButton}">
                <Grid x:Name="_Container" Background="#00000000">
                    <ContentPresenter x:Name="MyContentPresenter" Content="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center" />
                    <Path x:Name="_Icon" SnapsToDevicePixels="True" ToolTip="Close window" Width="18" Height="18" Margin="0" HorizontalAlignment="Center" VerticalAlignment="Center" Stretch="Fill" Stroke="#4D4D4D" StrokeThickness="1" Data="M0,0 L1,1 M0,1 L1,0" />
                </Grid>

                <ControlTemplate.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter TargetName="_Container" Property="Background" Value="#80FF0000" />
                        <Setter TargetName="_Icon" Property="Stroke" Value="#2D2D2D" />
                    </Trigger>

                    <Trigger Property="IsChecked" Value="True">
                        <Setter Property="local:WindowBehaviours.Close" Value="True" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

EDIT:

Ok, the exception seems to be thrown with any tooltip and not just the togglebutton, even with the UI Debugging Tools for XAML which is very unusual.

EDIT 2:

These are the resources i'm using

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Resources/Objects/Customviewer.xaml"/>
            <ResourceDictionary Source="Resources/Objects/CustomScroller.xaml"/>
            <ResourceDictionary Source="Resources/Objects/CustomButtons.xaml"/>
            <ResourceDictionary Source="Resources/Rooks/Alising.xaml"/>
            <ResourceDictionary Source="Resources/Themes/VisualOne.xaml"/>
            <ResourceDictionary Source="Resources/Themes/VisualDark.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

EDIT 3:

<Popup> is also having the same problem with the same exception thrown.


Solution

  • The problem was within the auto-generated resource file itself, it got corrupted somehow. Deleting it and regenerating a new one solved the problem.