【问题标题】:UWP Hamburger navigation menu error when using visual triggers - XAML使用可视触发器时出现 UWP Hamburger 导航菜单错误 - XAML
【发布时间】:2016-07-14 11:40:52
【问题描述】:

我正在使用可视触发器为 UWP 创建汉堡导航 UI,但出现此错误。 “一个动画正试图修改一个名为‘HamburgerButtonMobile’的对象,但在页面中找不到这样的对象。” 这是我的代码

 <VisualState.Setters>
    <Setter Target="HamburgerButtonMobile.Visibility" Value="Collapsed" />
</VisualState.Setters>
<Pivot x:Name="MoviesPivot" Title="MOVIES">
    <Pivot.TitleTemplate>
        <DataTemplate>
            <RelativePanel>
                    <TextBlock Text="{Binding}" FontSize="72" Foreground="#FF21B255" FontWeight="Light" RelativePanel.AlignRightWithPanel="True" x:Name="titleName"/>
                    <Button x:Name="HamburgerButtonMobile" FontFamily="Segoe MDL2 Assets" Content="&#xE700;" Width="50" Height="50" Background="Transparent" Click="HamburgerButtonMobile_Click" RelativePanel.LeftOf="titleName" RelativePanel.AlignVerticalCenterWithPanel="True" />
            </RelativePanel>
        </DataTemplate>
</Pivot.TitleTemplate>

【问题讨论】:

    标签: c# xaml uwp uwp-xaml


    【解决方案1】:

    您的可视触发器看不到该项目的原因是您尝试访问的项目位于DataTemplate 中。它“不存在”

    我认为您想要做的是将视觉触发器添加到RelativePanel。 老实说,不看更多代码很难说。

    <RelativePanel>               
       <VisualStateManager.VisualStateGroups>
          <VisualStateGroup>
               <VisualState x:Name="BlahNameState">
                 <VisualState.Setters>
                      <Setter Target="HamburgerButtonMobile.Visibility" Value="Collapsed" />
                 </VisualState.Setters>
    

    【讨论】:

    • 嗨,我尝试了您的解决方案,我不再收到错误,但它也没有隐藏按钮。我为枢轴之外的其他元素设置的视觉触发器完美地工作。
    • 好吧,如果你没有收到错误,那么你的第一个问题就解决了。我不能为你按摩代码大声笑
    猜你喜欢
    • 1970-01-01
    • 2021-10-30
    • 2019-09-30
    • 1970-01-01
    • 2016-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多