Bryan Ulfers
Bryan Ulfers

Reputation: 125

StaticResource reference 'Settings' was not found

A WPF application of mine has started throwing this error in the designer view for a window. It compiles and runs without issue, but will not load in designer.

The strangest part of the error, however, is that it only occurs on the first reference to settings. In the code below, if I comment out the first <Setter>, the error moves down to the next one. If I then uncomment that first <Setter>, the error moves back to it.

    <Style TargetType="{x:Type ComboBox}">
        <Setter Property="FontSize" Value="{Binding Source={StaticResource Settings}, Path=Default.setFontSize}" />
    </Style>
    <Style TargetType="{x:Type TextBox}">
        <Setter Property="FontSize" Value="{Binding Source={StaticResource Settings}, Path=Default.setFontSize}" />
    </Style>
    <Style TargetType="{x:Type Label}">
        <Setter Property="Foreground" Value="{Binding Source={StaticResource Settings}, Path=Default.setFontColor}" />
    </Style>

Any ideas?

Upvotes: 0

Views: 1044

Answers (2)

Thomas
Thomas

Reputation: 3560

I just came across the same issue. Here is how I solved it globally for the app in the App.xaml. Notice xmlns:properies and properties:Settings lines.

<Application x:Class="MyApp.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:properties="clr-namespace:MyApp.Properties"
         StartupUri="MainWindow.xaml">
<Application.Resources>
    <properties:Settings x:Key="Settings" />
</Application.Resources>

Upvotes: 1

Steoates
Steoates

Reputation: 3168

Hmm - that is very strange.. in your Xaml file, do you see any elements with the Settings keys?

maybe something is injecting it into the resource dictionary when it runs so that's why it builds and runs fine.

Upvotes: 0

Related Questions