0

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?

Bryan Ulfers
  • 125
  • 15

2 Answers2

1

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>

Thomas
  • 3,532
  • 3
  • 20
  • 22
0

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.

Steoates
  • 3,058
  • 5
  • 27
  • 43
  • No other elements are using the application settings from within the Xaml. It is used within the codebehind, but not the Xaml. – Bryan Ulfers Oct 23 '12 at 14:35
  • Any chance you could create a slim project that recreates this and ill have a play around? – Steoates Oct 23 '12 at 14:40
  • If you create a new WPF project, paste the code I posted above within tag and build it, the problem occurs. – Bryan Ulfers Oct 23 '12 at 14:45
  • This is in Visual Studio 2008 btw. Not sure if that makes a difference. – Bryan Ulfers Oct 23 '12 at 14:47
  • Can you try using x:Static instead for your class? Im guessing your class is static by the way - http://stackoverflow.com/questions/507942/what-does-xstatic-mean-in-xaml .. this may help. – Steoates Oct 23 '12 at 14:54
  • What I'm trying to access is the user/application settings file. This code had worked previously without issue. I did find another suggestion to add the following to app.xaml: `xmlns:properties="clr-namespace:WPFSettingsBugTest.Properties"`, then in Application.Resources: ``. This seems to have resolved the problem. Very odd that this would just randomly start happening, however. – Bryan Ulfers Oct 23 '12 at 15:01
  • Correction: This fixed the problem in the slim project I started, but this code was already in the original project, hence it does not resolve the problem there. – Bryan Ulfers Oct 23 '12 at 15:03
  • Ah yes, I thought you might have been using the build in settings but I wasnt sure - another member in your team hasnt created a conflicting class have they?.. just clutching at straws now :) – Steoates Oct 23 '12 at 15:08
  • Nope, this project is managed by myself. Nobody else works in it, and the only Settings class is the default one created by Visual Studio. It has not been edited at all. – Bryan Ulfers Oct 23 '12 at 15:15