WPF prompts "an exception is thrown when the value is provided on System. Windows. Markup. StaticResourceHolder,

Source: Internet
Author: User

WPF prompts "an exception is thrown when the value is provided on System. Windows. Markup. StaticResourceHolder,

When writing a program, the system keeps reporting the error shown in the question, prompting that a defined static resource cannot be found. Baidu realized the order of resource definition only after a while.

App. xaml is defined as follows:

<Application x:Class="WpfApp2.App"              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:WpfApp2"              StartupUri="FrmMain.xaml"              xmlns:d="http://schemas.microsoft.com/expression/blend/2008"              d1p1:Ignorable="d"              xmlns:d1p1="http://schemas.openxmlformats.org/markup-compatibility/2006">  <Application.Resources>        <ResourceDictionary>            <vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" xmlns:vm="clr-namespace:WpfApp2.ViewModel" />            <LinearGradientBrush x:Key="MainBrush" EndPoint="1,1" StartPoint="0,0">                <GradientStop Color="#242424" Offset="0"/>                <GradientStop Color="#101010" Offset="1"/>            </LinearGradientBrush>            <ResourceDictionary.MergedDictionaries>                <ResourceDictionary Source="/WpfApp2;component/Dictionary/Templete.xaml"/>                <ResourceDictionary Source="/WpfApp2;component/Dictionary/Style.xaml"/>                            </ResourceDictionary.MergedDictionaries>                    </ResourceDictionary>      </Application.Resources></Application>

As shown above, two resource dictionaries are defined: Templete. xaml and Style. xaml. The error occurs because Templete. xaml uses the Style defined in Style. xaml, but Style. xaml is defined after Templete, causing an exception. The solution is

Change the definition order of the resource dictionary file.

Conclusion: 1. The resource defined after the resource is used will cause an exception.

2. generally, it is best to place the paint brush, color, and defined local class at the beginning of the resource file, such as the MainBrush gradient Paint Brush defined in this example. If it is defined after the resource file is used, the exception shown in the title is also thrown.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.