为什么我的wpf资源字典在设计时没有解析但在运行时工作。 [英] Why is my wpf resource dictionary not resolving at designtime but works at run time.

查看:114
本文介绍了为什么我的wpf资源字典在设计时没有解析但在运行时工作。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在资源字典中为项目中的所有按钮定义了一个简单的样式。我正在引用App.xaml文件中的字典。如果我运行该项目一切正常,但在设计时App.xaml文件中有一个错误找到资源字典时发生错误Dictionary1.xaml。为什么它在设计时没有解决并阻止我看到设计更改,直到我运行项目。



这是我的资源字典中的代码



I have defined a simple style for all buttons in my project in a resource dictionary. I'm referencing the dictionary in the App.xaml file. If I run the project everything works fine, but at design time there is an error inside the App.xaml file "An error occurred while finding the resource dictionary "Dictionary1.xaml". Why is it not resolving at designtime and prevents me from seeing design changes untill I run the project.

Here is the code in my Resource Dictionary

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:ctMyButton">

    <Style TargetType="Button">
        <Setter Property="MinWidth" Value="50"/>
        <Setter Property="MinHeight" Value="23"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Grid>
                        <Ellipse Height="{TemplateBinding Height}" Width="{TemplateBinding Width}" Fill="{TemplateBinding Background}"/>
                        <TextBlock Text="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center" ></TextBlock>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>





这里是App.xaml代码



And here is the App.xaml code

<Application x:Class="ctMyButton.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:ctMyButton"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Dictionary1.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>





我的尝试:



我已经尝试过研究这个问题,但是对于这个确切的问题没有答案,并且只是假设字典正在解析。



What I have tried:

I have tried researching the problem but there are no answers for this exact question and any walk through just assume the dictionary is resolving.

推荐答案

这个 链接你可以找到答案
In this link you can find answer


这篇关于为什么我的wpf资源字典在设计时没有解析但在运行时工作。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆