Bind Grid.Row / Grid.Column inside a DataTemplate

后端 未结 1 842
隐瞒了意图╮
隐瞒了意图╮ 2020-12-05 11:37

Hope this is not a dupe.

I would like to be able to do the following in XAML:

        
            


        
相关标签:
1条回答
  • 2020-12-05 11:52

    Solved it myself with help from the blogs.

    As far as I understand you simply can't do the attached property binding inside.

    The following solves the problem in an instant (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>
    
    0 讨论(0)
提交回复
热议问题