The resource "SearchBoxStyle" could not be resolved - silverlight

I am recieving following error in VS 2010.
I have two Silverlight projects. one project only contains styles and other project is my application. I have referenced styles project in my application and user static resources from that project in my whole application, but I keep recieving this error in VS though everything works fine when I compile and run the application.
The resource "SearchBoxStyle" could not be resolved

Yes, I stumped on this one today and I am also looking for a solution.
It seems to be a missing feature of Visual Studio - VS XAML designer just cannot find static resources outside of the current XAML file.
It seems, Expression Blend is smarter and offers a workaround for such cases.
Here is a similar thread which suggests using Blend:
The resource could not be resolved (VS 2010 RC)
And here is what Microsoft says about this issue:
http://msdn.microsoft.com/en-us/library/bb546934(VS.90).aspx#ResourcesatDesignTime
And for me the solution was to put a / in the path of my resource and set the xaml file to compile as a resource. So my App.xaml looks like this:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Resources/ControlStyles.xaml" />
</ResourceDictionary.MergedDictionaries>
<!-- Dummy Style for WPF 4 bug fix, anything you won't use goes -->
<Style TargetType="{x:Type WebBrowser}" />
</ResourceDictionary>
</Application.Resources>
It failed to load at design time when I did not use the first slash in the path, but now it works fine at design time in other XAML pages.

Related

Modern UI (WPF): Trying to use MUI for a WPF control in class library

I'm trying to use MUI framework for a existing WPF control (the WPF control is in class library). I've looked the MUI example for a modern window and tried to copy the resourceDictionary I found in the App.xaml.
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/ModernUI.xaml" />
<ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/ModernUI.Light.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
The issue that at design time, the UI seems to be have changed (look at the data)
but during running time, I'm getting exception (xamlparse exeption) that has an inner exception saying it was unable to locate the file or assembly FirstFloor.ModernUI.
I've used nuget to include the MUI framework the dll's copy to local is true.
I've also tried
<ResourceDictionary Source="pack://application:,,,/FirstFloor.ModernUI;component/Assets/ModernUI.xaml" />
<ResourceDictionary Source="pack://application:,,,/FirstFloor.ModernUI;component/Assets/ModernUI.Light.xaml"/>
and it doesn't work.
Any help would appreciated!
pack://application: apparently scope to the calling application. In my case the compiled dll was called from an exectuable (3rd party vendor SOLIDWORKS). I had to copy paste the FirstFloor.ModernUI dll in the folder of the SOLIDWORKS executable that solves the problem.
If anyone can provide a better answer (that doesn't involve this manually intervention), I'll tick their answer.

WPF Resource is not found by ReSharper in design time but solution builds

I use ReSharper 8.2.3 Full Edition with Visual Studio Ultimate 2013 and .NET 4.5.
The background is that I have a C# WPF solution with a large number of projects. To simplify the description here, I have the following projects:
Project 1: Library with UI resources (styles, fonts etc), including a resource dictionary named ResourceLibrary.xaml.
Project 2: Main exe with some WPF user controls/views and an app.xaml. The WPF user controls do NOT refer directly to ResourceLibrary.xaml in project 1. The IntelliSense works fine and ReSharper does NOT generate any warnings (blue squiggly lines).
Project 3: Library with some WPF user controls/views. All these user controls refer to ResourceLibrary.xaml:
<UserControl.Resources>
<ResourceDictionary Source="/<my_resource_namespace>;component/ResourceLibrary.xaml" />
</UserControl.Resources>
The IntelliSense works fine and ReSharper does NOT generate any warnings (blue squiggly lines).
The solution builds fine, IntelliSense works (finds the static resources in ResourceLibrary.xaml) and ReSharper does not generate any warnings.
However, if the above lines are removed, IntelliSense does not work and ReSharper generates the warning "Resource XXX is not found". Note that this is NOT the case with the XAML files in project 2 that also uses resources in the resource library. The solution builds fine.
I want to avoid to include the resource library in every XAML file due to performance reasons but I do want ReSharper to give me relevant warnings. Is there a workaround to this problem?
I know I can turn the "The resource XXX is not found" warnings off in the ReSharper, but that would prevent me from detecting real resource problems.
You might have solved this already, but this is the solution I used for my own project.
If you add a new WPF User Control in Project 3, change it to Application (and in the code behind) and add your reference to the Resource Library from there, Resharper stops complaining.
A bit of a hack, but the code is never executed and at least you don't need to modify every single controller.
<Application x:Class="Namespace.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<!-- Remove Resharper warning about "Resource ... is not found" and allow navigation/refactoring-->
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Namespace.Infrastructure;component/SystemStyles/Styles.xaml"></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>

Theme in MergedDictionary in Silverlight not working design time

Ok, this is driving me crazy now. I have a Silverlight 5 project. Not long ago we decided to theme our project, just to make it pop more. I found a theming implementation and went ahead.
First i used the .Theming namespace from the Silverlight Toolkit. I used the explicitly build theme.dll's. There was a shortcoming with this though, that i didnt have the ability to customize the theme. So i decided to just use the theme.xaml instead, and implement it by using <MergedDictionaries>.
The problem with this approach though, is that i lost the ability to see the theme in design time. In runtime it works fine. But that's just not good enough, when i wan't to customize the theme.
I implemented the theme by using merged dictionaries in App.Xaml like so
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/eCP;component/Themes/WhistlerBlue.xaml"/>
</ResourceDictionary.MergedDictionaries>
<vm:ViewModelLocator x:Key="ViewModelLocator"/>
</ResourceDictionary>
</Application.Resources>
If i put the same blok in my MainPage, the theme instantly turns on in design time there. But it shouldnt be necessary to do it on every Silverlight page?
So in short: If i implement the theme in with MergedDictionaries in App.xaml it does not work in design time. If i do it on a specific page, it does work.
Funny thing though, if i open my project in Expression Blend, it works fine in design time.
My first notion is, that something is messing with my visual studio 2010 SP1. Maybe something in a hidden project file or something, but i don't know.
Anyone able to help?

WPF - using styles/resources from another assembly

I'm new to WPF and struggling to use styles that live in a separate assembly. This is what I'm doing:-
I have a class library project with a \Themes folder containing a "generic.xaml" that merges a number of xaml files from a subfolder within \Themes:-
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Metro\CoreStyles.xaml" />
... etc ...
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
My solution also has a WPF application project, and in here the App.xaml merges in the resources from my library project like so:-
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MyThemeLibrary;component/Themes/generic.xaml"/>
... etc...
Standard stuff so far.
Finally, I have a third project - a WPF user control library. These controls use these common styles, typically with "Style={StaticResource SomeStyle}". I can run the app and it all looks fine, but the problem is I don't get design-time support when writing the user controls - the design surface is basically empty.
Another SO article suggested adding an App.xaml to the user control library project, and merging in the resources as above. This works and I get my design-time support, however I get an error when trying to build the solution:
Library project file cannot specify ApplicationDefinition element.
I have tried changing the App.xaml build action from "ApplicationDefinition" to "Page", as has been suggested elsewhere. This gets the build working but I lose the design-time support as the user controls can no longer see the styles.
Is there a way around this problem, or failing this, an alternative way of using styles from another assembly?
Thanks in advance
Andrew
The error message says it. You cannot use "pack://application..." syntax in a library project. You should do this in your wpf project.

Unable to attach multiple styles in Visual Studio 2008

Helo!
I create in my project a folder named 'Templates'.
In this folder I store all my DataTemplates declared in various ResourceDictionary files.
I am attaching it (so it becomes a StaticResource and I can use it everywhere in the
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Templates/ContactTemplate.xaml"/>
<ResourceDictionary Source="/Templates/ProductTemplate.xaml"/>
<ResourceDictionary Source="/Templates/OrderTemplate.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
I have many templates, and in some of theme I want to use another template, e.g. in the OrderTemplate I need to use the ContactTemplate and vice versa.
The problem is that Visual Studio 2008 (Yes, it works in run-time, and Expression Studio doesn't notify a problem) reports errors about these templates and doesn't want to show the designer (it does compile tho).
VS loads the templates in the order as they're merged in the App.xaml file, for example, in the OrderTemplate I may use ContactTemplate but not vice versa.
I tried mergin the OrderTemplate individually in the ContactTemplate but then after I do so in various templates, it becomes circular and I get a SO exception.
Any experience to share? I need design-time support.
Thanks
I don't know if I made the right decision, but I changed the circular references from StaticResource to DymaicResource and everything works fine now.

Resources