d:DesignData FileNotFoundException

时间:2013-09-05 08:30:13

标签: wpf visual-studio-2010 abstract-class design-data

我尝试使用DesignData在设计时填充ItemsControl。

文件/DesignData/SampleAlerts.xaml的内容是:

<ext:AlertSource xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:ext="http://schemas.osterwalder.com/extensions"
             mc:Ignorable="d" d:IsDataSource="true" Guid="4D0E0886-575C-42F2-A777-2A36AB826D14" Name="Sample Alerts">
<ext:AlertSource.Alerts>
    <ext:AlertBase Cause="sdlfkhjsdlkfj" Id="0" IsActive="True" IsAutoReset="False" IsOwnerAlive="False" Message="skdjfhsdakjhf" Removal="skjfdhkjsdfhs" Severity="SystemFault" Source="{x:Null}"/>
    <ext:AlertBase Cause="sdlfkhjsdlkfj" Id="0" IsActive="True" IsAutoReset="False" IsOwnerAlive="False" Message="skdjfhsdakjhf" Removal="skjfdhkjsdfhs" Severity="EmergencyStop" Source="{x:Null}"/>
    <ext:AlertBase Cause="sdlfkhjsdlkfj" Id="0" IsActive="True" IsAutoReset="False" IsOwnerAlive="False" Message="skdjfhsdakjhf" Removal="skjfdhkjsdfhs" Severity="ImmediateStop" Source="{x:Null}"/>
    <ext:AlertBase Cause="sdlfkhjsdlkfj" Id="0" IsActive="True" IsAutoReset="False" IsOwnerAlive="False" Message="skdjfhsdakjhf" Removal="skjfdhkjsdfhs" Severity="CycleStop" Source="{x:Null}"/>
    <ext:AlertBase Cause="sdlfkhjsdlkfj" Id="0" IsActive="True" IsAutoReset="False" IsOwnerAlive="False" Message="skdjfhsdakjhf" Removal="skjfdhkjsdfhs" Severity="Warning" Source="{x:Null}"/>
</ext:AlertSource.Alerts>

文件/DesignData/SampleAlerts.xaml的构建操作设置为DesignData。

当我尝试在UI中使用此设计数据时:

    <CollectionViewSource x:Key="AlertGroups" 
                          mc:Ignorable="d" d:DesignSource="{d:DesignData Source=/DesignData/SampleAlerts.xaml}">
        <CollectionViewSource.GroupDescriptions>
            <PropertyGroupDescription PropertyName="Severity"/>
        </CollectionViewSource.GroupDescriptions>
        <CollectionViewSource.SortDescriptions>
            <scm:SortDescription PropertyName="Severity" Direction="Descending"/>
        </CollectionViewSource.SortDescriptions>
    </CollectionViewSource>

在VisualStudio中,一切都很好,但我在visual studio designer中得到以下Exception:

The resource 'file:///C:/Users/reto/Documents/Visual Studio 2010/Projects/PPS/HMI/DesignData/SampleAlerts.xaml#3' could not be found. It should be located at 'C:\Users\reto\Documents\Visual Studio 2010\Projects\PPS\HMI\DesignData\SampleAlerts.xaml#3' but the file is not present.
   at MS.Internal.Providers.VSExternalResourceProvider.GetTextModel(String uri, FileModel relativeTo)
   at MS.Internal.Host.Isolation.Adapters.ContextToProtocolAdapter.MS.Internal.Host.Isolation.Protocols.IExternalResourceProtocol.GetTextModel(String uri, IFileModel relativeTo)
   at MS.Internal.Host.Isolation.Protocols.IExternalResourceProtocol.GetTextModel(String uri, IFileModel relativeTo)
   at MS.Internal.Host.Isolation.Adapters.ToExternalResourceAdapter.GetTextModel(String uri, FileModel relativeTo)
   at MS.Internal.Host.MarkupProjectContext.GetMarkupResourceImpl(Uri uri)
   at MS.Internal.Host.MarkupProjectContext.GetMarkupResource(Uri uri)
   at Microsoft.Windows.Design.DocumentModel.MarkupDocumentManagerBase.TreeChangeListener.Microsoft.Windows.Design.DocumentModel.IDocumentTreeConsumer.HandleMessage(DocumentTreeCoordinator sender, MessageKey key, MessageArguments args)
   at Microsoft.Windows.Design.DocumentModel.MarkupDocumentManagerBase.CancelableDocumentTreeCoordinator.RouteMessage[T](IDocumentTreeConsumer consumer, MessageKey`1 key, T args)
   at Microsoft.Windows.Design.DocumentModel.DocumentTreeCoordinator.SendMessage[T](MessageKey`1 key, T args, Boolean isPrivateMessage)
   at Microsoft.Windows.Design.DocumentModel.DocumentTreeCoordinator.SendMessage[T](MessageKey`1 key, T args)
   at Microsoft.Windows.Design.DocumentModel.DocumentTreeCoordinator.QueryValue[TResult,TParameter](QueryKey`2 key, IDocumentTreeConsumer consumer, TParameter parameter)
   at Microsoft.Windows.Design.Platform.ViewProducerBase.MS.Internal.Platform.IResourceResolver.GetMarkupResource(Uri uri)
   at MS.Internal.Platform.CiderProjectContext.ResolveMarkupResource(Uri uri, Func`2 fallbackResolver)
   at Microsoft.Windows.Design.Platform.ViewProducerBase.GetExternalView(String path)
   at Microsoft.Windows.Design.Platform.ViewProducerBase.Microsoft.Expression.DesignModel.DocumentModel.IDocumentRootResolver.GetDocumentRoot(String path)
   at Microsoft.Expression.DesignModel.InstanceBuilders.DesignDataInstanceBuilder.Instantiate(IInstanceBuilderContext context, ViewNode viewNode)
   at Microsoft.Expression.DesignModel.Core.ViewNodeManager.Instantiate(ViewNode viewNode)

在Blend eveything中也很好,但设计师显示以下错误: - 类型'AlertSource'是抽象的,必须包含显式值。 Ln 1 Col 0 - 会员'警报'无法识别或无法访问。 Ln 7 Col 4

类型AlertSource和AlertBase是具有以下骨架的抽象类:

public abstract class AlertBase : IAlert
{
    public long Id { get { ... } }

    public abstract object Message { get; }

    public abstract object GetLocalizedMessage(CultureInfo culture);

    public abstract object Cause { get; }

    public abstract object GetLocalizedCause(CultureInfo culture);

    public abstract object Removal { get; }

    public abstract object GetLocalizedRemoval(CultureInfo culture);

    public AlertSource Source { get { ... } }
    AlertSource IAlert.Source { get { ... } }

    public bool IsOwnerAlive { get { ... } }

    public bool IsActive { get { ... } set { ... } }

    public abstract bool IsAutoReset { get; }

    public abstract AlertSeverity Severity { get; }

    public void Acknowledge() { ... }

    public AlertBase(long id, AlertSource owner) { ... }

    public event EventHandler Set;

    public event EventHandler Reset;

    public event EventHandler Acknowledged;
}

public abstract class AlertSource : IAlertSource
{
    public abstract Guid Guid { get; }

    public abstract string Name { get; }

    public ICollection<IAlert> Alerts { get { ... } }

    public AlertSource() { ... }

    public virtual bool Acknowledge(IAlert alert) { ... }

    public event NotifyCollectionChangedEventHandler CollectionChanged;

    public event EventHandler AlertSet;
    public event EventHandler AlertReset;
    public event EventHandler AlertAcknowledged;

    public IEnumerator<IAlert> GetEnumerator() { ... }

    IEnumerator IEnumerable.GetEnumerator() { ... }
}

有人知道如何解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

这只是一个奇怪的WPF编译器错误,一旦您构建了项目,它就会消失。即使一个与WPF XAML代码错误无关的单一错误也可能导致WPF中出现这种奇怪的错误。

所以我建议您首先在XAML中注释导致该错误的所有行,而不是查找阻止编译项目的原始错误。然后在XAML中取消注释行。