Sinatr
Sinatr

Reputation: 21969

XAML designer can't locate resource

I've custom control in shared project (resource dictionary in shared project).

Everything works fine in run time, xaml designer however throws exception:

Cannot locate resource 'mycontrol.xaml'.

The problem occurs when loading style for control:

public class MyControl: Control
{
    public MyControl()
    {
        Resources = new ResourceDictionary() { Source = new Uri("pack://application:,,,/mycontrol.xaml") };
        Style = (Style)Resources["somekey"];
    }
}

Why does it works in run-time and doesn't during design time?

I can detect design time, but what to do then?

Upvotes: 4

Views: 2249

Answers (2)

c0d3b34n
c0d3b34n

Reputation: 563

I would try

Uri res = new Uri("pack://siteoforigin:,,,/mycontrol.xaml", UriKind.Relative);
Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = res });

Upvotes: 0

makzr
makzr

Reputation: 355

The WPF designer seems to have problem when loading xaml files from other projects. Could you try to load the xaml file using this annotation:

pack://application:,,,/PROJECTNAMESPACE;component/mycontrol.xaml

Upvotes: 5

Related Questions