在设计模式下将项添加到wpf DataGrid

时间:2016-04-25 10:03:09

标签: c# wpf datagrid

我有一种复杂的类型(带嵌套类)

namespace Restore
{
    public class Item
    {
        public string Title { get; set; }
        public ImageSource Image { get; set; }
    }

    public class ItemSummary
    {
        public ImageSource Status { get; set; }
        public Item Item { get; set; }
        public string Description { get; set; }
    }
}

我的xaml

<Window x:Class="Restore.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:Restore"

    <Window.Resources>
        <BitmapImage x:Key="Error" UriSource="../../Images/Error.png" />
    </Window.Resources>

    <DataGrid>
        <DataGrid.Columns>
            <DataGridTemplateColumn Header="Status" Width="45" >
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <Image Source="{Binding Status}" Width="16" Height="16" />
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>
            <DataGridTemplateColumn Header="Object" Width="*">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <Image Source="{Binding Item.Image}" Width="16" Height="16" />
                            <TextBlock Text="{Binding Item.Title}" />
                        </StackPanel>
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>
            <DataGridTextColumn Header="Description" Width="*" Binding="{Binding Description}" />
        </DataGrid.Columns>
        <local:ItemSummary Item="{???}" Status="{StaticResource Error}" Description="1 item" />
        <local:ItemSummary Item="{???}" Status="{StaticResource Success}" Description="2 item" />
        <local:ItemSummary Item="{???}" Status="{StaticResource Warning}" Description="3 item" />

    </DataGrid>
</Window>

我不知道如何将项目值设置为Item="{???}"

0 个答案:

没有答案