How to enable static development-time resources in embedded UserControls in Blend 4

Short version How do you handle static resource searches in UserControls that are embedded in other windows / user / custom controls? So Blend 4 can do it right @ the development time that Visual Studio is already doing for you.

Long version As follows from this question, we have a window in which there are built-in user controls, and the window, as well as each, as a built-in user control, use extensions for extensions of static resources to resolve links to resources found in the combined dictionary in the app.xaml file.

Blend has no problem loading and rendering any of my custom controls that I created on the surface of VS Designer when opened separately. It has no problems resolving the myriad of static resources that I use almost everywhere.

Whenever I try to open my "MainWindow.xml", (window control), I notice that I get errors 4 - I canโ€™t create an instance of the type , and Blend 4 tells me beautifully about ArtBoard that it caught some exceptions in time design. Digging further into these exceptions, attaching an instance of the VS debugger to Blend, I noticed that every static resource I referenced complained that it could not find it.

As a comparison, I looked at the user control that I created, it did not use any static resources, although they were local resources. This user control, when it was built into UserControl, I noticed that it works very well. I think this is obvious why!

Is there anyone in this, have any ideas how to get around this? I tried everything "Add a development-time dictionary" <- which works partially, the built-in user controls are still not created at all!

Study

UPDATE: Possible Solutions:

. = (

+5
3

Converters.xaml, Blend . , xaml .

using System;
using System.ComponentModel;
using System.IO;
using System.Windows;
using System.Windows.Markup;

public static class DesignTimeSupport
{
    public static void LoadCommonConvertersForBlend(this ResourceDictionary resourceDictionary)
    {
        if (resourceDictionary == null || !DesignerProperties.IsInDesignTool) return;

        var convertersXamlUri = new Uri("Assets/Converters.xaml", UriKind.Relative);
        var streamInfo = Application.GetResourceStream(convertersXamlUri);
        using (var reader = new StreamReader(streamInfo.Stream))
        {
            var converters = (ResourceDictionary)XamlReader.Load(reader.ReadToEnd());
            resourceDictionary.MergedDictionaries.Add(converters);
        }
    }
}

ViewBase .

public class ViewBase : Page
{
    public ViewBase()
    {
        Resources.LoadCommonConvertersForBlend();
    }
}

, ViewBase, .

+1

- . , , . , , , .

+1

( ), , "maindictionary.xaml", "MainDictionary.xaml",.

, FileName manidictionary.xaml, MainDictionary.xaml , ... .

, - , , .

0
source

All Articles