我在下面编写了一个代码示例:
<StackPanel>
<TextBlock>Appointments today</TextBlock>
<ItemsControl ItemsSource="{Binding Appointments}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<controls:CalendarMonthDayEventsItemsPanel OutsideViewportCount="..." />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border>
<TextBlock Text="{Binding Title}" />
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<StackPanel Orientation="Horizontal">
<TextBlock>+</TextBlock>
<TextBlock Text="{Binding ......}" /> <!-- Should show number of items in ItemsControl that are outside view, using CalendarMonthDayEventsItemsPanel.OutsideViewportCount -->
<TextBlock>more items</TextBlock>
</StackPanel>
</StackPanel>我创建了一个定制的面板,CalendarMonthDayEventsItemsPanel,并使用该面板作为ItemsControl的项目表。在面板的布局代码中,我确定有多少项(面板childs)超出了面板的界限。属性OutsideViewportCount包含在CalendarMonthDayEventsItemsPanel可见边界之外的项数。
现在,我想在低于OutsideViewportCount的TextBlock中显示ItemsControl的值。
这意味着我必须创建某种绑定,但我尝试的一切都无法工作。有人有一个解决方案或更好的方法来实现同样的结果吗?
发布于 2022-04-02 17:25:38
也许您可以使用ItemsPanel的Tag属性来传递ItemsPanel的值作为解决方案。
<ItemsControl x:Name="A"
ItemsSource="{Binding Appointments}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<local:CalendarMonthDayEventsItemsPanel OutsideViewportCount="{Binding RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}, Path=Tag, Mode=OneWayToSource}"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
...
</ItemsControl>
<StackPanel Orientation="Horizontal">
<TextBlock>+</TextBlock>
<TextBlock Text="{Binding ElementName=A, Path=Tag, Mode=OneWay}"/>
<TextBlock>more items</TextBlock>
</StackPanel>https://stackoverflow.com/questions/71718791
复制相似问题