如何隐藏数据透视项?
我有一个带有 Pivot
控件的页面,在某些情况下我不想显示特定的 PivotItem
。
将 Visibility
设置为折叠似乎根本不会影响它。
有什么建议吗?
I have a Page with an Pivot
-control and in some cases I don't want to show a particular PivotItem
.
Setting the Visibility
to collapsed doesn't seem to affect it at all.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
您应该能够通过使用 Pivot.Items 上的相应集合方法在数据透视表中动态删除或添加 PivotItems 。
如果这不适用于您的场景,请告诉我。
you should be able to remove or add PivotItems dynamically in your Pivot by using the respective collection methods on Pivot.Items .
Let me know if this doesn't work for your scenario.
我创建了一个自定义行为来显示/隐藏枢轴项目
用法:
代码:
I've created a custom behavior for showing/hiding pivot item
Usage:
Code:
您可以从父透视控件中删除透视项
You can remove the pivot item from the parent pivot control
删除 PivotItems 很容易,但如果您想稍后将它们放回去,我发现标题会变得混乱并开始相互重叠。如果您将标题的可见性设置为折叠,然后再次使其可见,也会发生这种情况。
因此,我通过将每个不需要的 PivotItem(及其标题)的不透明度设置为 0 来解决我的特定问题。
但是,这会在丢失的 PivotItem 所在的位置留下间隙。
对我来说,间隙不是问题,因为我只想删除 PivotItemList 末尾的项目,因此最后一个和第一个 PivotItems 之间有一些空白。问题是,我仍然能够滑动到隐藏的 PivotItem。为了解决这个问题,我重写了 Pivot.SelectionChanged() ,以便每当用户滑动到隐藏的 PivotItem 时,代码就会移至下一个项目。我必须在 SelectionChanged() 中使用 DispatchTimer,并实际上从 DispatchTimer 回调移动到下一个 PivotItem,因为您必须在 UI 线程中才能更改 PivotItem.SelectedIndex。
Removing PivotItems is easy, but if you want to put them back afterwards I've found that the headers get messed up and start overlapping each other. This also happens if you set the Visibility of a header to Collapsed and then later make it Visible again.
So I solved my particular problem by setting the opacity of each unwanted PivotItem (and its header) to 0.
However, this leaves gaps where the missing PivotItems are.
For me, the gaps were not a problem because I only want to remove items at the end of my PivotItemList, so I get some whitespace between the last and first PivotItems. The problem was, I was still able to swipe to a hidden PivotItem. In order to fix this, I overrode Pivot.SelectionChanged() so that whenever the user swipes to a hidden PivotItem, the code moves on to the next item instead. I had to use a DispatchTimer from within SelectionChanged() and actually move to the next PivotItem from the DispatchTimer callback, since you have to be in the UI thread to change PivotItem.SelectedIndex.
将 IsLocked 属性设置为 true 将使除当前数据透视项之外的所有其他数据透视项消失。
但这不会隐藏我们选择的一个特定的关键项目。
Setting
IsLocked
property to true will make all other Pivot items to disappear except the current pivot item.But this will not hide one particular pivot item of our choice.
详细说明添加/删除pivotItems而不是隐藏它们的解决方案。
假设我们希望pivotItem 最初是不可见的,并且仅在特定事件上出现。
然后,为了再次添加它,
我使用“插入”而不是“添加”来控制选项卡出现的位置。
您必须确保不会两次添加相同的选项卡,这就是 if 语句的原因。
To elaborate on the solution of adding/removing pivotItems, rather than hiding them.
Let's say we want the pivotItem to be initially invisible, and appear only on a certain event.
Then to add it again,
I've used Insert rather than add to control the position where the tab appears.
You have to ensure you don't add the same tab twice, which is the reason for the if statement.
我修改了 Bajena 行为来改进它,解决了重复显示/隐藏时丢失 PivotItem 原始位置的问题以及父透视控件为空(尚未初始化)时的问题。
请注意,此行为必须附加到数据透视表,而不是数据透视表项。
代码:
用法:
I've modified the Bajena behavior to improve it, solving the issue with losing the original position of the PivotItem when showing/hiding repeteadly and the issue when parentpivot control is null (not initialized yet).
Notice that this behavior must be attached to the Pivot, not to the PivotItem.
Code:
Usage: