1

I'm trying to change the Background of a Grid by using a Visual State and a Staticresouce as the value in the Setter of the Visual State. It works just fine at Runtime but the designer shows the following error (which doesn't help me a lot):


Exception: Der Text zu diesem Fehlercode wurde nicht gefunden. (unknown error)

Stacktrace: at Windows.UI.Xaml.Hosting.XamlUIPresenter.Render() at Microsoft.VisualStudio.DesignTools.WindowsXamlDesigner.Views.WindowsUIXamlImageHost.RenderWorker() at Microsoft.VisualStudio.DesignTools.WindowsXamlDesigner.Views.WindowsUIXamlImageHost.RenderScheduler.OnRender(Object object) at Microsoft.VisualStudio.DesignTools.WindowsXamlDesigner.Views.WindowsUIXamlImageHost.RenderScheduler.b__26_0(Object o) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

Invalid attribute value Unknown for property Background. InnerException: None


This is what I tried:

<Grid x:Name="grid">
    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="TestGroup">
             <VisualState x:Name="TestState">
                  <VisualState.Setters>
                       <Setter Target="grid.(Panel.Background)" Value="{StaticResource BackgroundBrush}" />
                  </VisualState.Setters>
             </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
</Grid>


<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <SolidColorBrush x:Key="BackgroundBrush" Color="Black"/>
</ResourceDictionary>


<App>
    ...
    <App.Resources>
         <ResourceDictionary>
              <ResourceDictionary.MergedDictionaries>
                   <ResourceDictionary Source="Resources/Test.xaml"/>
              </ResourceDictionary.MergedDictionaries>
         </ResourceDictionary>
    </App.Resources>
</App>

enter image description here

Cort3vl
  • 163
  • 1
  • 11

1 Answers1

0

The current Blend is really buggy so I am not surprised if you see errors like this.

One workaround is, reopen your page that contains this resource in Blend. You should see a dialog popping up (see below image). Then select your Test.xaml file from the Available dictionaries dropdown and hit OK.

enter image description here

By doing so blend will generate a DesignTimeResources.xaml file under your project Properties and it should eliminate the error on the designer.


However, I also noticed that your <ResourceDictionary.MergedDictionaries> isn't wrapped within a <ResourceDictionary>. Shouldn't it be something like this instread?

<App.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Resources/Test.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</App.Resources>

Update

This is indeed a Blend bug which even happens with built-in resources. To replicate, try building the project and then go to the States tab and select a VisualState, right after you will see the Blend Designer crashed. Note that I have Run project code in XAML Designer (if supported) turned off.

Currently the only way to remove the crash is to reopen the xaml file.

Justin XL
  • 38,763
  • 7
  • 88
  • 133
  • Thanks I'll give it a try. So this is not a mistake of mine but a bug in Blend? This would be great news because it's akward defining all those setters without the designer just by typing them in. The missing ResourceDictionary is just a copy-paste error, I removed all the unnecessary parts, sry. – Cort3vl Aug 17 '15 at 11:09
  • If it works, then it could be a Blend bug. I'm not exactly sure how you structure your files but the issue seems to be that Blend couldn't locate that *Test.xaml* resource dictionary file. However, I just tried to create a demo project and did exactly what you described, it worked fine. Blend didn't complain. – Justin XL Aug 17 '15 at 11:16
  • I added a screenshot of the error message. I even tried it with a build-in resource and still the same error. – Cort3vl Aug 17 '15 at 11:25
  • `BackgroundAltBrushMedium` is not a built-in resource is it? Try using another `ThemeResource` instead. – Justin XL Aug 17 '15 at 11:28
  • Added another screenshot, still the same error. I just picked BackgroundAltBrushMedium from the resources I could pick on the property window while editing the Visual State so I guess it is, I haven't defined a resource with this key. – Cort3vl Aug 17 '15 at 11:38
  • No, that's also wrong. You should be using a `Brush` instead of `Color`. – Justin XL Aug 17 '15 at 11:39
  • I'm sorry my bad. Now it should be right but the error's still there. – Cort3vl Aug 17 '15 at 11:45
  • I'd suggest you to try removing parts in your project to locate what the issue really is. Is it a new project? Is it a project that migrated from earlier version of WinRT? – Justin XL Aug 17 '15 at 11:46
  • I copied parts of an old WinRT project but the project itself was created a week ago using Visual Studio 2015 RTM. I'll create a fresh project and try it out. – Cort3vl Aug 17 '15 at 11:49
  • Yeah, what I also noticed is that in the new uwp, we have `` but you have ` – Justin XL Aug 17 '15 at 11:51
  • Another copy-paste mistake. So I've created a fresh new project. I've done nothing but adding a VisualState with the Setter from the screenshot above. After building the project and selecting the Visual State in the state window of blend the exact same error occured. – Cort3vl Aug 17 '15 at 11:59
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/87162/discussion-between-justin-xl-and-cort3vl). – Justin XL Aug 17 '15 at 12:00