如果你想設置的時候啓動應用程序,你可以在OnLaunched事件中使用下面的代碼的背景圖像:你在哪裏運行代碼
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
Frame rootFrame = Window.Current.Content as Frame;
// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();
rootFrame.Background = new ImageBrush
{
Stretch = Windows.UI.Xaml.Media.Stretch.UniformToFill,
ImageSource = new BitmapImage { UriSource = new Uri("ms-appx:///Assets/Image.jpg") }
};
if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
//TODO: Load state from previously suspended application
}
// Place the frame in the current Window
Window.Current.Content = rootFrame;
}
if (rootFrame.Content == null)
{
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
if (!rootFrame.Navigate(typeof(MainPage), args.Arguments))
{
throw new Exception("Failed to create initial page");
}
}
// Ensure the current window is active
Window.Current.Activate();
}
?你確定'路徑'指向一些有效的圖像嗎? –
我寫了一個名爲changeBackground的函數,當我按下主頁上的按鈕時,我會調用它。我知道該圖像位於我的資產文件夾中。 – Mirimari