I'm trying to add a resource dictionary to a page but I keep getting a designer error in my xaml. The app runs fine with no issue but the designer error bothers me.
Here's how I did it. Both works fin at run time. But it's saying Failed to set "Source". Any clues?
That also gives an error to all the static resource I used from the resource dictionary.
Update:
This is another approach. Instead of directly adding it to the Page's resources, I added it to the Application.Resources still cant resolve the styles. I'm using VS2017 v15.4.4
Steps to reproduce:
- List item
- Create a new UWP Application Project (App1)
- Create a new UWP Class Library (ClassLibrary1)
- In ClassLibrary1, add a new ResourceDictionary (Dictionary1.xaml).
In Dictionary1.xaml, add a Style, let's say a button style.
<Style TargetType="Button" x:Name="ButtonStyle1" x:Key="ButtonStyle1"> <Setter Propeprty="Background" Value="Red" /> </Style>
In the ClassLibrary1, add a new BlankPage (BlankPage1)
- In the BlankPage1, add a button and use ButtonStyle1 `
- In App1, merge the resource dictionary to App.Resources (inside App.xaml).
<Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionary> <ResourceDictionary Source="ms-appx:///ClassLibrary1/Dictionary1.xaml" /> </ResourceDictionary.MergedDictionary> </ResourceDictionary> </Application.Resources>
Make the BlankPage1 the start page, go to App.xaml.cs and and change MainPage to BlankPage1:
if (e.PrelaunchActivated == false) { if (rootFrame.Content == null) { // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation // parameter rootFrame.Navigate(typeof(BlankPage1), e.Arguments); } // Ensure the current window is active Window.Current.Activate(); }
Run the application. It will run just fine. But the problem is in the designer where it cannot recognize the style from the resource dictionary.
I followed your steps and found a typo and an issue.
The typo: In Style step (Perhaps only in the sample), There is typo in the word 'Proeprty':
The issue in the way you are merging dictionary, it should be using the following syntax:
After fixing both issues, Visual studio designer didn't complain about anything.
Did it fix the issue for you? If not then your steps to reproduce aren't complete.