You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS2022 WPF .NET中如何修复XDG0062错误?

解决Error XDG0062: 'StaticResourceExtension' is not valid for Setter.Value的问题

问题根源

你在ControlTemplate.xaml里用StaticResource引用了EditorColors.xaml中的画笔资源,但两个资源字典之间没有建立合并引用关系,导致XAML解析器无法找到这些资源,进而抛出该错误(错误信息表述存在误导,本质是资源未被正确解析)。

修复方法

  1. 在ControlTemplate.xaml的ResourceDictionary节点内部添加对EditorColors.xaml的合并引用:
<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="EditorColors.xaml"/>
</ResourceDictionary.MergedDictionaries>

若两个文件不在同一目录,需调整Source路径(例如使用包路径/Pico_Editor.Dictionaries;component/EditorColors.xaml)。

  1. 确保主窗口的资源字典正确引入这两个文件,或直接引用包含它们的合并字典,保证主窗口使用PicoWindowStyle时能找到所有依赖资源。

修改后的ControlTemplate.xaml示例

<ResourceDictionary x:Class="Pico_Editor.Dictionaries.ControlTemplates"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:Pico_Editor.Dictionaries">
    
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="EditorColors.xaml"/>
    </ResourceDictionary.MergedDictionaries>
    
    <Style TargetType="{x:Type TextBox}" x:Key="TextBoxStyle">
        <!-- TODO: define the look of textbox here -->
    </Style>

    <Style TargetType="{x:Type TextBox}" x:Key="{x:Type TextBox}" BasedOn="{StaticResource TextBoxStyle}">
        <EventSetter Event="KeyDown" Handler="OnTextBox_KeyDown"/>
    </Style>

    <Style x:Key="PicoWindowStyle" TargetType="{x:Type Window}">
        <Setter Property="BorderBrush" Value="{StaticResource Editor.Selected.BackgroundBrush}"/>
        <Setter Property="Background" Value="{StaticResource Editor.Window.GrayBrush1}"/>
    </Style>
</ResourceDictionary>

备选方案

若合并后仍存在加载顺序问题,可临时替换为DynamicResource(性能略逊,但能延迟资源查找,适配加载顺序场景):

<Setter Property="BorderBrush" Value="{DynamicResource Editor.Selected.BackgroundBrush}"/>
<Setter Property="Background" Value="{DynamicResource Editor.Window.GrayBrush1}"/>

内容的提问来源于stack exchange,提问作者Daniel McLarty

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 22:30:33