【问题标题】:Programmatically change page background in Windows 8 Metro App以编程方式更改 Windows 8 Metro App 中的页面背景
【发布时间】:2013-05-29 22:50:04
【问题描述】:

我是 Windows 8 开发的新手,我一直在纠结这个问题。基本上,我有主页,我想在每次启动应用程序时更改其背景图像。请帮忙!!!!

【问题讨论】:

  • 如果它是基于 html 的 windows 商店应用程序,您可以使用 css background 属性
  • 我使用 XAML 和 C#,我是 C# 新手,我试过 this.Frame ((Frame) this.Content).Background = new ImageBrush { ImageSource = new BitmapImage(new Uri("ms -appx:///Assets/GameBG/bg1_1366x768.jpg")) };但它不起作用,我得到了 NullPointerException :(。有什么想法吗?

标签: windows-8 microsoft-metro background-image


【解决方案1】:

在您的ViewModel 中创建一个Uri,并让您的BackgroundImageBrush 绑定到此Uri。然后,在应用启动时,让您的应用使用您想要的任何逻辑将Uri 更改为您想要的任何新图像。

此外,当使用您在 cmets 中提到的 ImageSource 时,您应该使用 SetSource

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多