0

I try to use DesignData to populate a ItemsControl in Design Time.

The content of the file /DesignData/SampleAlerts.xaml is:

<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>

And the build action of the file /DesignData/SampleAlerts.xaml is set to DesignData.

When i try to use this design data in the 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>

In VisualStudio everything builds fine, but I get the following Exception in the visual studio designer:

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)

And also in Blend eveything builds fine but the designer shows the following errors: - The Type 'AlertSource' is abstract and must include an explicit value. Ln 1 Col 0 - The member 'Alerts' is not recognized or not accessible. Ln 7 Col 4

The type AlertSource and AlertBase are abstract classes with the following skelettons:

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;
}

and

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() { ... }
}

Does someone know how to solve this problem?

1 Answers1

0

It's just a strange WPF compiler error and it dissappears once you have your project built. Even one single not relevant to WPF XAML code error can cause such strange error in WPF.

So I recommend that you first comment all lines in XAML that cause that error, than find original errors that block compilation of project. And then uncomment lines in XAML.

Kolya Evdokimov
  • 331
  • 4
  • 5