我如何知道选择了哪个 HubSection [英] How can I tell which HubSection is selected

查看:36
本文介绍了我如何知道选择了哪个 HubSection的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户更改 Hub 控件中的视图时,我需要更改 AppBar 的内容.

I need to change the contents of an AppBar when a user changes the view in a Hub control.

我在使用 Pivot 控件时的做法是侦听 SelectionChanged 事件并响应 SelectIndex 值.

The way I did it while using a Pivot control is listening to the SelectionChanged event and responding to the SelectIndex value.

但是,集线器只有一个 SectionsInViewChanged 事件,它返回多个部分的集合.通常是一个用户与之交互,然后是相邻的、几乎不可见的部分.

The hub, however, only has a SectionsInViewChanged event, which returns a collection of multiple sections. Usually the one user is interacting with and then the adjacent, barely-visible section.

所以我的问题是,我如何知道哪个部分是当前突出显示给用户的部分(以便我可以相应地更改 AppBar 图标)?

So my question is, how can I tell which Section is the one that is currently being prominently displayed to the user (so I can change the AppBar icons accordingly)?

推荐答案

在 Hub 控件中,我们可以监听 SectionsInViewChanged 事件.我们可以通过这个获取显示在屏幕上的 HubSection:

In Hub control, We can listen to the SectionsInViewChanged event. We can get the HubSection which is displayed in screen by this:

var section = hubDemo.SectionsInView[0];

hubDemo 是我的 Hub 控件的名称.我们可以为每个 HubSection 设置 Tag 属性.例如:

hubDemo is the name of my Hub control. And we can set Tag property for each HubSection. For example:

<Hub x:Name="hubDemo" SectionsInViewChanged="demoHub_SectionsInViewChanged">
    <HubSection Tag="0" Header="Section1" Width="800"/>
    <HubSection Tag="1" Header="Section2" Width="400"/>
    <HubSection Tag="2" Header="Section3" Width="400"/>
    <HubSection Tag="3" Header="Section4" Width="400"/>
    <HubSection Tag="4" Header="Section5" Width="600"/>
</Hub>

所以我们可以通过标签来改变 AppBar 的内容:

So we can change AppBar content by tag:

private void demoHub_SectionsInViewChanged(object sender, SectionsInViewChangedEventArgs e)
{
    var section = hubDemo.SectionsInView[0];
    var tag = section.Tag.ToString();
    switch (tag)
    {
        // Change your AppBar by tag
    }
}

这篇关于我如何知道选择了哪个 HubSection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆