将app.xaml拆分为多个文件时出现问题 [英] Problem when splitting app.xaml into several files

查看:118
本文介绍了将app.xaml拆分为多个文件时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将app.xaml分成几个xaml文件。它似乎适用于大多数事情,但不适用于clr-namespace的事情。我开始将app.xaml中的所有内容移动到另一个文件中。我将尝试用一个小例子来解释。



App.xaml

I try to split app.xaml into several xaml-files. It seems to work for most things, but not for things reffering to clr-namespace. I started out by moving "everything" from app.xaml to another file. I'll try to explain with a small example.

App.xaml

<Application x:Class="Preparation.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:src="clr-namespace:Preparation.DataModel" 
             xmlns:conv="clr-namespace:Preparation.Converters"
             xmlns:viewmodel="clr-namespace:Preparation.ViewModel"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="AppRevision.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>

    </Application.Resources>
</Application>





AppRevision.xaml



AppRevision.xaml

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:src="clr-namespace:Preparation.DataModel" 
             xmlns:conv="clr-namespace:Preparation.Converters"
             xmlns:viewmodel="clr-namespace:Preparation.ViewModel"
>

    <!-- <conv:DateConverter x:Key="dateConverter"/>
    <conv:IntToStringConverter x:Key="IntToOvenSeqMode" FalseValue="Hold"   TrueValue="Ramp" />-->

    <Style x:Key="titleStyle" TargetType="TextBlock">
        <Setter Property="FontWeight" Value="Bold"/>
        <Setter Property="Foreground" Value="DodgerBlue"/>
        <Setter Property="FontSize" Value="18"/>
    </Style>

    <DataTemplate DataType="{x:Type src:TableHandler}">
     ...
    </DataTemplate>
</ResourceDictionary> 





我可以编译项目,但在启动时我在DataType上收到以下消息:



I can compile the project, but when starting it I get the following message at the DataType:

System.Windows.Markup.XamlParseException
InnerException: {"Type reference can't find any type with name {clr-namespace:Preparation.DataModel}TableHandler."}





如果我不喜欢注释掉DateConverter,我在那里得到了类似的错误。



奇怪的是当代码在app.xaml里面时它可以工作。

我猜这是一个简单的错误,但我找不到它。



If i don't comment out the DateConverter, I get a similar error there instead.

The odd thing is that it works when the code is inside app.xaml.
I guess that it's a simple error, but I haven't been able to find it.

推荐答案

我自己发现了错误。

由于某种原因,我必须指定程序集。

app.xaml中不需要。



I found the error myself.
I have to specify the assembly also for some reason.
It wasn't required in app.xaml.

<resourcedictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:src="clr-namespace:Preparation.DataModel;assembly=Preparation" 
             xmlns:conv="clr-namespace:Preparation.Converters;assembly=Preparation"
             xmlns:viewmodel="clr-namespace:Preparation.ViewModel;assembly=Preparation"
></resourcedictionary>





也许在其他地方有一个我不知道的设置。



Maybe there is a setting somewhere else that I don't know about.


这篇关于将app.xaml拆分为多个文件时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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