Я получаю сообщение об ошибке в файле ресурсов xaml при сборке. Вот файл xaml:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="clr-namespace:DiagramDesigner"
xmlns:c="clr-namespace:DiagramDesigner.Controls"
xmlns:r="clr-namespace:Automation.Data;assembly=Automation"
xmlns:a="clr-namespace:Automation;assembly=Automation" >
<DataTemplate x:Key="WorkflowDropdownSetting">
<DataTemplate.Resources>
<s:WorkflowDropdown x:Key="settingFlowList" />
</DataTemplate.Resources>
<StackPanel Orientation="Horizontal">
<ComboBox ItemsSource="{StaticResource settingFlowList}" Width="200" SelectedValue="{Binding Path=DefaultValue, Mode=TwoWay}" DisplayMemberPath="Name" SelectedValuePath="Id"/>
<Button x:Name="btnEditWorkflow" Command="{x:Static s:WorkflowUICommands.EditWorkflow}" CommandParameter="{Binding Path=DefaultValue}">Edit...</Button>
</StackPanel>
</DataTemplate>
</ResourceDictionary>
А вот и источник для WorkflowList.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Automation;
using System.Collections.ObjectModel;
using Automation.Data;
namespace DiagramDesigner
{
public class WorkflowList : ObservableCollection<Workflow>
{
public WorkflowList()
{
AutomationDataContext cntxt = Engine.Data;
IEnumerable<Workflow> lst = Engine.Data.Workflows.AsEnumerable<Workflow>();
foreach (Workflow flow in lst)
{
Add(flow);
}
}
}
}
Я использую этот объект как ресурс в другом xaml (не файл ресурсов), и он отлично работает:
<Window x:Class="DiagramDesigner.WorkflowMain"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="clr-namespace:DiagramDesigner"
Title="WorkflowMain" SizeToContent="Width" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">
<ScrollViewer Grid.IsSharedSizeScope="True">
<ScrollViewer.Resources>
<ResourceDictionary>
<s:WorkflowList x:Key="flows"/>
<Brush x:Key="BrdrBrush">#D6FF9436</Brush>
<Style TargetType="TextBlock">
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="VerticalAlignment" Value="Stretch"/>
</Style>
<Style TargetType="WrapPanel">
<Setter Property="Margin" Value="2"/>
<Setter Property="Background" Value="PowderBlue"/>
<Setter Property="VerticalAlignment" Value="Stretch"/>
</Style>
<Style x:Key="Heading" TargetType="TextBlock">
<Setter Property="FontSize" Value="20"/>
<Setter Property="FontWeight" Value="bold"/>
</Style>
<Style x:Key="ColumnHeader" TargetType="Label">
<Setter Property="FontWeight" Value="bold"/>
</Style>
</ResourceDictionary>
</ScrollViewer.Resources>
<Border BorderThickness="1"
Padding="4"
BorderBrush="{StaticResource BrdrBrush}"
Background="AliceBlue"
SnapsToDevicePixels="True" HorizontalAlignment="Stretch">
<StackPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="Job"></ColumnDefinition>
<ColumnDefinition SharedSizeGroup="Name"></ColumnDefinition>
<ColumnDefinition SharedSizeGroup="Description"></ColumnDefinition>
<ColumnDefinition SharedSizeGroup="FirstAction"></ColumnDefinition>
<ColumnDefinition SharedSizeGroup="Button"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<WrapPanel Grid.Row="0" Grid.ColumnSpan="5">
<TextBlock Text="Workflows:" Style="{StaticResource Heading}"/>
</WrapPanel>
<WrapPanel Grid.Column="0" Grid.Row="1">
<Label Style="{StaticResource ColumnHeader}">Name:</Label>
</WrapPanel>
<WrapPanel Grid.Column="1" Grid.Row="1">
<Label Style="{StaticResource ColumnHeader}">Name:</Label>
</WrapPanel>
<WrapPanel Grid.Column="2" Grid.Row="1">
<Label Style="{StaticResource ColumnHeader}">Description:</Label>
</WrapPanel>
<WrapPanel Grid.Column="3" Grid.Row="1">
<Label Style="{StaticResource ColumnHeader}">First Task:</Label>
</WrapPanel>
<WrapPanel Grid.Column="4" Grid.Row="1">
</WrapPanel>
</Grid>
<ItemsControl ItemsSource="{Binding Source={StaticResource flows}}" Grid.Row="2" Grid.ColumnSpan="5" HorizontalAlignment="Stretch">
<ItemsControl.Template>
<ControlTemplate>
<ItemsPresenter SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Margin="0,5,0,5"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<DataTemplate.Resources>
<Style TargetType="{x:Type WrapPanel}">
<Setter Property="Margin" Value="2"/>
<Setter Property="Background" Value="PowderBlue"/>
<Setter Property="MinHeight" Value="30" />
<Setter Property="VerticalAlignment" Value="Stretch"/>
</Style>
</DataTemplate.Resources>
<Grid Background="AliceBlue" Margin="0 0 0 5" HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="Job"></ColumnDefinition>
<ColumnDefinition SharedSizeGroup="Name"></ColumnDefinition>
<ColumnDefinition SharedSizeGroup="Description"></ColumnDefinition>
<ColumnDefinition SharedSizeGroup="FirstAction"></ColumnDefinition>
<ColumnDefinition SharedSizeGroup="Button"></ColumnDefinition>
</Grid.ColumnDefinitions>
<WrapPanel>
<TextBlock Text="{Binding Path=Name}" Grid.Column="1"/>
</WrapPanel>
<WrapPanel>
<TextBlock Text="{Binding Path=Job.Name}" Grid.Column="0"/>
</WrapPanel>
<WrapPanel Grid.Column="2">
<TextBlock Text="{Binding Path=Description}"/>
</WrapPanel>
<WrapPanel Grid.Column="3">
<TextBlock Text="{Binding Path=FirstAction.Name}"/>
</WrapPanel>
<WrapPanel Grid.Column="4">
<Button Name="editButton" Command="{x:Static s:WorkflowUICommands.EditWorkflow}" CommandParameter="{Binding}" IsDefault="True" VerticalAlignment="Stretch">Edit...</Button>
</WrapPanel>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<Button Name="btnNewWorkflow" Command="{x:Static s:WorkflowUICommands.NewWorkflow}" >New Workflow...</Button>
</StackPanel>
</Border>
</ScrollViewer>
</Window>
При сборке я вижу эту ошибку:
Error 5 Missing key value on 'WorkflowDropdown' object. C:\Source\Projects\devtest\UI\WorkflowUI\DiagramDesigner\Resources\SettingTemplates.xaml 7 2 DiagramDesigner
Единственный вопрос , который я мог найти относительно этой ошибки, не относится, потому что я уже использую x: Key.
Решение работает просто отлично, но ошибка не позволяет конструктору быть интерактивным. Он отображается нормально до тех пор, пока вы не попытаетесь с ним взаимодействовать, а затем отключен, за исключением перечисленного сверху исключения:
XamlObjectWriterException was thrown on "DataTemplate":Missing key value on 'WorkflowList' object. Click here to hide detail.
An Unhandled Exception has occurred
Missing key value on 'WorkflowList' object.
at System.Xaml.XamlObjectWriter.GetKeyFromInstance(Object instance, XamlType instanceType, IAddLineInfo lineInfo)
at System.Xaml.XamlObjectWriter.Logic_DoAssignmentToParentCollection(ObjectWriterContext ctx)
at System.Xaml.XamlObjectWriter.Logic_DoAssignmentToParentProperty(ObjectWriterContext ctx)
at System.Xaml.XamlObjectWriter.WriteEndObject()
at System.Xaml.XamlWriter.WriteNode(XamlReader reader)
at System.Windows.Markup.WpfXamlLoader.TransformNodes(XamlReader xamlReader, XamlObjectWriter xamlWriter, Boolean onlyLoadOneNode, Boolean skipJournaledProperties, Boolean shouldPassLineNumberInfo, IXamlLineInfo xamlLineInfo, IXamlLineInfoConsumer xamlLineInfoConsumer, XamlContextStack`1 stack, IStyleConnector styleConnector)
at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
Любая помощь будет принята с благодарностью, так как я, кажется, просто вращаю свои колеса.