我正在尝试在 ItemsControl 中绑定 UniformGrid Columns 属性。
到目前为止,我有:
<ScrollViewer x:Name="scroll" VerticalScrollBarVisibility="Auto">
<ItemsControl ItemsSource="{Binding}" >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid>
<UniformGrid.Columns>
<MultiBinding Converter="{StaticResource Columns}">
<Binding RelativeSource="{RelativeSource Self}" />
<Binding Source="{x:Reference scroll}" />
</MultiBinding>
</UniformGrid.Columns>
</UniformGrid>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</ScrollViewer>
在转换器中:
const double TileWidth = 154;
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
double width, aWidth;
UniformGrid grid = values[0] as UniformGrid;
ScrollViewer scroll = values[1] as ScrollViewer;
var gw = grid.Width;
var gaw = grid.ActualWidth;
aWidth = scroll.ActualWidth;
width = aWidth - (scroll.Padding.Left + scroll.Padding.Right);
return 3;
// return width / TileWidth;
}
我无法获得父控件的任何宽度来确定我想显示多少列。它们要么是0.0
要么NaN
。
如何获得父母的宽度以确定有多少可用空间?