0

I have discovered the given key was not present in the dictionary issue. I'm seeing this behaviour:

  • the preview in the xaml editor is sometimes shown. Sometimes it shows an exeption
  • the error list shows the given key was not present in the dictionary error.

I have defined a user conrtol which I initialize after it has beend loaded using the UserControl_loaded() callback.

    private void UserControl_Loaded(object sender, RoutedEventArgs e)
    {
        if (TraceGroup != TRACE_GROUP.NONE)
        {
            Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(MyDictionary[TraceGroup].Foreground));
            Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(MyDictionary[TraceGroup].Background));
            TraceGroupName = Globals.filterGroups[TraceGroup].Name;
        }
    }   

The initialization will be base on sone data I'm storing in a dictionary.
I assume, the xaml preview runs the UserControl_Loaded() in teh background when it generates the preview of my UI. The error occures, because the used Dictinary in the callback is only filled on startup of the app.
To get around this issue during preview-generation I have added the check if TraceGroup is defined. if (TraceGroup != TRACE_GROUP.NONE)...
But that does not solve my problem.

I'm using Visual Studio Professional 2013 and .Net 4.5.50938

thowa
  • 590
  • 1
  • 8
  • 29

0 Answers0