如果下面的代码没有很好的格式化,很抱歉。我把它从我的手机上发出来,因为我的无线网络目前有问题。
我想做这样的事情(我知道这样是不可能的):
...
<RowDefinition Height="Auto" ActualHeight="{Binding RowHeight, Mode="OneWayToSource"}"/>
...因此,高度基本上是自动的(因为它中的项的可能数量(例如标签)是0-n -使用ItemsControl表示),但我需要知道项控件的确切高度(在本例中是行),以计算表示数据所需的“页面”数量。就像word女士的书页一样。
然而,命名行(theRow.ActualHeight)是不可能的,因为VM / MVVM一般不应该这样做(无论如何,我不能直接访问视图)
知道怎么做吗?谢谢。
发布于 2014-08-08 17:07:47
这就是我所拥有的,而且它似乎奏效了。此外,我还复制了在this帖子中找到的this:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Text="This is row 1" Grid.Row="0"></TextBlock>
<ItemsControl Grid.Row="1"
vm:SizeObserver.Observe="True"
vm:SizeObserver.ObservedHeight="{Binding ActHeight, Mode=OneWayToSource}">
<TextBlock Text="1"></TextBlock>
<TextBlock Text="2"></TextBlock>
<TextBlock Text="3"></TextBlock>
<TextBlock Text="4"></TextBlock>
<TextBlock Text="5"></TextBlock>
<TextBlock Text="6"></TextBlock>
</ItemsControl>
<TextBlock Text="This is row 3"
Grid.Row="2"></TextBlock>
</Grid>在我看来,模型:
public double ActHeight
{
get
{
return _height;
}
set
{
_height = value;
}
}因为ItemsControl是第1行中的唯一元素,所以我们知道行的定义或行的高度将是行内控件的实际高度-- ItemsControl。
https://stackoverflow.com/questions/25174746
复制相似问题