Bind Grid.Row/Grid.Column внутри DataTemplate

Надеюсь, это не обман.

Я хотел бы иметь возможность сделать следующее в XAML:

<DataTemplate DataType="{x:Type TestApp:ButtonVM}">        
        <Button 
                Grid.Column="{Binding GridColumn}" 
                Grid.Row="{Binding GridRow}" 
                Content="{Binding Path=Info}" 
        />
</DataTemplate>

Связывание содержимого отлично работает, но Grid.Column и Grid.Row просто не существуют в созданном объекте. Даже когда я устанавливаю их в какое-то значение без привязки (например, в Grid.Column = "1" ). Я просмотрел приложение и увидел, что внутри моей сетки никто никогда не устанавливает Grid.Column и Grid.Row.

Любые идеи?

Ответ 1

Решил сам с помощью блогов.

Насколько я понимаю, вы просто не можете использовать привязанную привязку к объекту внутри.

Ниже решается проблема в одно мгновение (ItemContainerStyle!):

<DataTemplate DataType="{x:Type TestApp:GridVM}">
        <ItemsControl ItemsSource="{Binding Path=Children}">
            <ItemsControl.ItemContainerStyle>
                <Style>
                    <Setter Property="Grid.Row" Value="{Binding GridRow}" />
                    <Setter Property="Grid.Column" Value="{Binding GridColumn}" />
                </Style>
            </ItemsControl.ItemContainerStyle>
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <Grid ShowGridLines="True"  Style="{Binding Path=Style}">
                        <Grid.RowDefinitions>
                            <RowDefinition Height=".5*" />
                            <RowDefinition Height=".5*" />                            
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width=".5*" />
                            <ColumnDefinition Width=".5*" />
                        </Grid.ColumnDefinitions>                        
                    </Grid>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
        </ItemsControl>
</DataTemplate>