Cannot find resource with name / key

I am trying to use the unit test user interface using the Silverlight 4 Toolkit.

When I try to instantiate a UserControl, it throws an exception because the XAML UserControl uses the style defined by App.xaml.

Is there a way to load a resource somehow before I create an instance of UserControl? Am I going about it wrong?

Here's the unit test code:

        [TestMethod]
    public void ExerciseTimePeriodUserInterface()
    {
        CustomUserControls.TimePeriodFilter timePeriodFilter = new CustomUserControls.TimePeriodFilter();
    }

Here is a link to the style in UserControl:

<Border Style="{StaticResource FilterBorderWrapper}">

And finally, here is the style defined in App.xaml:

    <Style TargetType="Border" x:Key="FilterBorderWrapper">
        <Setter Property="Background" Value="#F1F5FB" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="BorderBrush" Value="#CBD9E9" />
        <Setter Property="CornerRadius" Value="2" />
        <Setter Property="Margin" Value="2" />
    </Style>
+3
source share
3 answers

ResorceDictionaries. . :

Application _app = new Application();
ResourceDictionary dictionary = new ResourceDictionary();
dictionary.Source = new Uri("pack://application:,,,/Gui.Mvvm;component/Themes/YourResourceDictionary.xaml");
_app.Resources.MergedDictionaries.Add(dictionary);

WPF . , , , DataTemplate .. , ,

Application.Current.FindResource()

.

+1

unit test . .

( , ), Silverlight ( , GUI).

VC 74, MVVM, , , ( Silverlight).

0

Rick,

, . Test-Projects App.xaml ( Styles.xaml), .

, "", , , . , .

Thomas

0
source

Source: https://habr.com/ru/post/1764923/


All Articles