绑定到附加属性Grid.Row和Grid.Column [英] Binding to attached property Grid.Row and Grid.Column
本文介绍了绑定到附加属性Grid.Row和Grid.Column的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要绑定到一个附加的属性,如Grid.Row和Grid.Column,但似乎它不工作。
我试过多个选项,但没有运气,下面是xaml的细节。
I need to bind to an attached properties like Grid.Row and Grid.Column but it seems that it is not working. I tried multiple options but no luck , below are the xaml details.
<Grid>
<Grid>
<Grid vm:GridHelper.RowCount="{Binding RowCount}"
vm:GridHelper.ColumnCount="2" />
<ItemsControl ItemsSource="{Binding ControlCollection}">
<ItemsControl.ItemContainerStyle>
<Style>
<Setter Property="Grid.Row" Value="{Binding Path=Row}" />
<Setter Property="Grid.Column" Value="{Binding Path=Column}" />
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Text}" Margin="5,5,20,5" FontSize="12"
TextWrapping="WrapWithOverflow"
Foreground="#AEAEAE" FontFamily="Tahoma" VerticalAlignment="Center"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
推荐答案
Grid.Row 和 Grid.Column
setters在ItemContainerStyle有效,你必须使用一个Grid作为 ItemsPanel $
In order to make the Grid.Row
and Grid.Column
setters in the ItemContainerStyle effective, you have to use a Grid as ItemsPanel
of the ItemsControl:
<ItemsControl ItemsSource="{Binding ControlCollection}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid>
<Grid.RowDefinitions>
...
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
...
</Grid.ColumnDefinitions>
</Grid>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
...
</ItemsControl>
这篇关于绑定到附加属性Grid.Row和Grid.Column的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文