WPF数据绑定:如何将ItemsCollection中的项绑定到Grid.Row和Grid.Column?

Bor*_*ris 6 wpf binding

我有一节课:

public class TempClass
{
    public int Row
    {
        get { return row; }
        set { row = value; }
    }
    public int Column
    {
        get { return column; }
        set { column = value; }
    }
    public string Value
    {
        get { return this.value; }
        set { this.value = value; }
    }

    int row;
    int column;
    string value;

    public TempClass(int row, int column, string value)
    {
        this.row = row;
        this.column = column;
        this.value = value;
    }
}
Run Code Online (Sandbox Code Playgroud)

我已经创建了一个List<TempClass> DummyCollection并且我已将其绑定到了ItemsControl.在ItemsControl使用UniformGrid的面板ItemsPanel属性.这是XAML代码:

<ItemsControl ItemsSource="{Binding Path=DummyCollection}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <UniformGrid Rows="3" Columns="5" />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemTemplate>
        <DataTemplate DataType="TempClass">
            <Border>
                <TextBlock Text="{Binding}" />
            </Border>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>
Run Code Online (Sandbox Code Playgroud)

我希望能够绑定TempClass物品在特定的细胞ItemsControl,也就是我想设置Grid.RowGrid.Column物品容器的性能相匹配Row,并Column在属性TempClass物品.我如何实现这一目标?谢谢.

Ken*_*art 7

<ItemsControl>
    <ItemsControl.ItemContainerStyle>
        <Style>
            <Setter Property="Grid.Row" Value="{Binding Row}"/>
            <Setter Property="Grid.Column" Value="{Binding Column}"/>
        </Style>
    </ItemsControl.ItemContainerStyle>
    ...
</ItemsControl>
Run Code Online (Sandbox Code Playgroud)