2

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.

Explisam
  • 749
  • 13
  • 26
  • At least enlighten me with the reason for your -1? – Explisam Jun 13 '17 at 16:17
  • Somewhere in your code, probably in any of your resource dictionaries, you have a {StaticResource} markup extension that refers to a resource that cannot be located. You need to provide a full repo of your issue for anyone to be able to help you any further: https://stackoverflow.com/help/mcve. You probably got the downvote because you did not provide a repo. – mm8 Jun 14 '17 at 13:38
  • @mm8 I reviewed all recent changes since last working build and nothing was pointed to a non existent resource. That which was the core of the problem that whoever downvoted didn't even mind to investigate. – Explisam Jun 14 '17 at 14:10

2 Answers2

0

Its working fine at my place...I guess you are missing something while getting 'DefaultStyle' .

XAML-

<UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../Style/Styles.xaml"/>
                <ResourceDictionary x:Name="DefaultStyle" 
                 Source="Dictionary1.xaml">               
                </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources> 

Everything whatever you mentioned as XAML Code is in my 'Dictionary1.xaml' and then i am using it in...

  <ToggleButton Name="CloseButton" Style="{StaticResource ToggleClose}" Grid.Row="1" Grid.Column="1"  />

also check your Dictionary and WindowBehaviours class error free..Please let me know if you still have the problem.

Lina
  • 163
  • 13
  • That's the problem, i don't have any styles with the name `DefaultSyle` and nothing is using the name. So, where did that come from? – Explisam Jun 13 '17 at 19:54
  • Strange!!!! May i know how you are using staticResource for togglebutton.. Error meight be related with that. – Lina Jun 13 '17 at 20:56
  • Lets forget about DefaultStyle . If we focus on exception ''System.Windows.Markup.StaticResourceHolder' threw an exception.' ... It ususlly cause due to incorrect order of resources. Please refer link - https://stackoverflow.com/questions/9994020/provide-value-on-system-windows-markup-staticresourceholder-threw-an-exception – Lina Jun 13 '17 at 21:16
  • I carefully checked everything but with no luck. Migrating the code to a new project solved it! No idea why. – Explisam Jun 15 '17 at 08:37
0

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

Explisam
  • 749
  • 13
  • 26