首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WPF绑定到ItemsPanel的ItemsControl属性

WPF绑定到ItemsPanel的ItemsControl属性
EN

Stack Overflow用户
提问于 2022-04-02 15:17:34
回答 1查看 147关注 0票数 -1

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

代码语言:javascript
复制
<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可见边界之外的项数。

现在,我想在低于OutsideViewportCountTextBlock中显示ItemsControl的值。

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-04-02 17:25:38

也许您可以使用ItemsPanelTag属性来传递ItemsPanel的值作为解决方案。

代码语言:javascript
复制
<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>
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71718791

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档