我在下面寫了一個代碼示例:
<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
這意味著我必須創建某種系結,但我嘗試的一切都不起作用。有人有解決方案或更好的方法來實作相同的結果嗎?
uj5u.com熱心網友回復:
也許您可以利用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>
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/455898.html
