![](/img/trans.png)
[英]How to change Grid.Row and Grid.Column attached property of content control in wpf
[英]Binding to attached property Grid.Row and Grid.Column
我需要綁定到諸如Grid.Row和Grid.Column之類的附加屬性,但似乎無法正常工作。 我嘗試了多種選擇,但是沒有運氣,下面是xaml的詳細信息。
<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
制定者在ItemContainerStyle有效,你必須使用一個網格, ItemsPanel
ItemsControl的的:
<ItemsControl ItemsSource="{Binding ControlCollection}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid>
<Grid.RowDefinitions>
...
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
...
</Grid.ColumnDefinitions>
</Grid>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
...
</ItemsControl>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.