ApplicationBar是一种类型,但在Panorama视图中用作变量

时间:2012-04-10 06:28:13

标签: c# silverlight windows-phone-7

我正在尝试在全景视图的代码中创建一个本地化的应用程序栏。这是我的代码:

// Helper function to build a localized ApplicationBar
        private void BuildApplicationBar()
        {
            // Set the page's ApplicationBar to a new instance of ApplicationBar.
            ApplicationBar = new ApplicationBar();

            ApplicationBar.Mode = ApplicationBarMode.Minimized;

            // Create a new button and set the text value to the localized string from AppResources.
            ApplicationBarIconButton homeButton = new ApplicationBarIconButton(new Uri("/Images/icons_home.png", UriKind.Relative));
            homeButton.Text = AppResources.HomeIcon;
            ApplicationBar.Buttons.Add(homeButton);
            homeButton.Click += new EventHandler(HomeButton_Click);

            ApplicationBarIconButton searchButton = new ApplicationBarIconButton(new Uri("/Images/appbar.feature.search.rest.png", UriKind.Relative));
            searchButton.Text = AppResources.SearchIcon;
            ApplicationBar.Buttons.Add(searchButton);
            searchButton.Click += new EventHandler(SearchButton_Click);
        }

但是,它无法将我的ApplicationBar识别为属性。错误说:'Microsoft.Phone.Shell.ApplicationBar'是'type',但用作'变量'。知道为什么吗?非常感谢!

费;

1 个答案:

答案 0 :(得分:2)

您的专有名称与其类型相同。重命名它。所以:

ApplicationBar ApplicationBar
{
  get;
  set;
}

ApplicationBar MyApplicationBar
{
  get;
  set;
}

ApplicationBar = new ApplicationBar();

this.MyApplicationBar = new ApplicationBar();

以及对this.MyApplicationBar

的适当性的任何其他提及