【问题标题】:PivotItem's Header keeps Saying FirstPivotItem 标头一直在说第一
【发布时间】:2015-12-31 07:56:35
【问题描述】:

每当我调试应用程序时,无论我对 PivotItem 的标头做什么,它都会说“first”,而 Pivot 的 Title 总是说“MY APPLICATION”。

代码:

PivotPage.xaml

<Pivot x:Uid="Pivot" Title="THE BOX" x:Name="pivot">
    <!--Pivot item one-->
    <PivotItem
        x:Uid="PivotItem1" Header="The Box" 
        Margin="19,14.5,0,0" CommonNavigationTransitionInfo.IsStaggerElement="True">
    </PivotItem>
</Pivot>

更新: 我在代码隐藏中没有发现任何影响这种行为的东西:

PivotPage.xaml.cs

public sealed partial class PivotPage : Page, INotifyPropertyChanged
{    
    private readonly NavigationHelper navigationHelper;
    private readonly ResourceLoader resourceLoader =
        ResourceLoader.GetForCurrentView("Resources");

    public event PropertyChangedEventHandler PropertyChanged;

    public PivotPage()
    {
        this.InitializeComponent();
        DataContext = this;
        this.NavigationCacheMode = NavigationCacheMode.Required;

        this.navigationHelper = new NavigationHelper(this);
        this.navigationHelper.LoadState += this.NavigationHelper_LoadState;
        this.navigationHelper.SaveState += this.NavigationHelper_SaveState;
    }

    /// <summary>
    /// Gets the <see cref="NavigationHelper"/> associated with this <see cref="Page"/>.
    /// </summary>
    public NavigationHelper NavigationHelper
    {
        get { return this.navigationHelper; }
    }

    private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
    {

    }

    private void NavigationHelper_SaveState(object sender, SaveStateEventArgs e)
    {
        // TODO: Save the unique state of the page here.
    }

    /// <summary>
    /// Adds an item to the list when the app bar button is clicked.
    /// </summary>
    private void AddAppBarButton_Click(object sender, RoutedEventArgs e)
    {
        Box = Note.MakeTable();
    }

    private void OnPropertyChanged(string property_name)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(property_name));
        }
    }

    #region NavigationHelper registration

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        this.navigationHelper.OnNavigatedTo(e);
    }

    protected override void OnNavigatedFrom(NavigationEventArgs e)
    {
        this.navigationHelper.OnNavigatedFrom(e);
    }

    #endregion

    private void MakeTable(object sender, TappedRoutedEventArgs e)
    {
        Box = Note.MakeTable();
    }

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        Box = Note.MakeTable();
    }
}

截图

【问题讨论】:

  • 这很奇怪! PivotPage.xaml 后面的代码中没有代码?确定加载的是那个页面,你删除了默认的 MainPage.xaml 并更改了 app.xaml.cs 中的启动?
  • 我会再检查一次,但我很确定没有任何与此相关的内容是代码隐藏。
  • @Depechie:不。什么都没有。
  • 而且不再有 MainPage.xaml?
  • @Depechie:不。这不是 WPF;这是 Windows 手机。

标签: c# xaml windows-phone-8.1


【解决方案1】:

您需要从控件中删除 x:Uid 参数才能使用指定的文本。

或者修改Resources.resw文件中的值。

【讨论】:

  • 是的,如果使用资源也可能是这种情况:)
  • @Roman:如果我在这里声明,为什么会这样?或者更好的是,x:Uid 对 Resources.resw 做了什么?
  • 没关系。单击了链接。那钉了它。谢谢! PivotPage 模板通过在新项目启动时添加所有这些额外的东西来与您一起玩。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-17
  • 2017-04-24
  • 2016-11-24
  • 2021-06-12
  • 1970-01-01
相关资源
最近更新 更多