WPF 绑定到 ItemsControl 的 ItemsPanel 的属性

用户2190492

我在下面写了一个代码示例:

<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在面板的布局代码中,我确定有多少项(面板子项)在面板边界之外。该属性OutsideViewportCount包含超出可见范围的项目数CalendarMonthDayEventsItemsPanel

现在我想显示低于OutsideViewportCount.TextBlockItemsControl

这意味着我必须创建某种绑定,但我尝试的一切都不起作用。有人有解决方案或更好的方法来实现相同的结果吗?

表情包

也许您可以利用Tag属性ItemsPanel来传递 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>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章