Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从“更新页面控件”;“设置”;飞出_C#_Windows 8_Microsoft Metro - Fatal编程技术网

C# 如何从“更新页面控件”;“设置”;飞出

C# 如何从“更新页面控件”;“设置”;飞出,c#,windows-8,microsoft-metro,C#,Windows 8,Microsoft Metro,我正在构建一个metro风格的应用程序。我设计了一个“设置”弹出按钮,用户可以在其中更改应用程序HomePageView页面中包含的文本块的字体 通过列出所有系统字体的组合框选择字体。选择字体后(在“设置”弹出按钮的组合框中),必须更新HomePageView页面中的所有文本块 这是要更新的样式(位于standardstyles.xaml中): 这是HomePageView.xaml.cs中更新文本块(时间小时)的SetTextBlockFont属性: 应用程序编译时没有错误,但当我单击组合框中

我正在构建一个metro风格的应用程序。我设计了一个“设置”弹出按钮,用户可以在其中更改应用程序HomePageView页面中包含的文本块的字体

通过列出所有系统字体的组合框选择字体。选择字体后(在“设置”弹出按钮的组合框中),必须更新HomePageView页面中的所有文本块

这是要更新的样式(位于standardstyles.xaml中):

这是HomePageView.xaml.cs中更新文本块(时间小时)的SetTextBlockFont属性:

应用程序编译时没有错误,但当我单击组合框中的字体时,什么也没有发生。我想是因为我必须加载HomePageView页面homePageViewReference的新实例,或者因为我必须重新加载页面或类似的内容


我指出我不能使用Frame对象或NavigationService类,因为这是一个metro应用程序。

您需要在视图中实现INotifyPropertyChanged,或者您可以直接使用LayoutWarePage提供的DefaultViewModel

Class A:INotifyPropertyChanged
{

    #region EventHandler
    public event PropertyChangedEventHandler PropertyChanged;

    public void RaisePropertyChanged(string propertyName)
    {
        if (this.PropertyChanged != null)
        {
            this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    #endregion
    public Style SetTextBlockFont
    {
        set
        {
            timeHour.Style = value;
            RaisePropertyChanged("SetTextBlockFont");
        }
    }
}

谢谢你的回答,但我还有问题。正如我在上面写的,我选择字体的组合框和我必须更改字体的文本块位于不同的页面中。我无法通知不同页面之间样式的更改。希望有人能帮助我。你可以保留一个singleton类,或者你可以使用app.xaml.cs并使用一个属性。所以,当你使用全局属性导航到一个页面时,你可以改变不同页面的样式。你能给我举个例子吗?我从未使用过全局属性和单例类。我知道,它们很少被使用。非常感谢你的帮助
private void fontBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var res = new ResourceDictionary()
            {
                Source = new Uri("ms-appx:///Common/StandardStyles.xaml", UriKind.Absolute)

            };
            var style = res["timeStyle"] as Style;

            style.Setters.RemoveAt(2);
            style.Setters.Add(new Setter(FontFamilyProperty, new FontFamily("Arial")));

            HomePageView homePageViewReference = new HomePageView();
            homePageViewReference.SetTextBlockFont = style;
        }
public Style SetTextBlockFont
        {
            set
            {
                timeHour.Style = value;
            }
        }
Class A:INotifyPropertyChanged
{

    #region EventHandler
    public event PropertyChangedEventHandler PropertyChanged;

    public void RaisePropertyChanged(string propertyName)
    {
        if (this.PropertyChanged != null)
        {
            this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    #endregion
    public Style SetTextBlockFont
    {
        set
        {
            timeHour.Style = value;
            RaisePropertyChanged("SetTextBlockFont");
        }
    }
}