簡體   English   中英

如何在Xamarin Forms中從ContentPage保存App.xaml中的資源?

[英]How to save resource in App.xaml from ContentPage in Xamarin Forms?

我有一個需要主題的Xamarin Forms應用程序,基本上我想要的是,當我打開我的應用程序時,有一個工具欄,其中有一個主題頁面,而主題頁面有一些按鈕,當我單擊按鈕時,它將改變背景整個應用的圖像。 問題是當我關閉並重新打開應用程序時,圖像不存在。

這是我的App.xaml

    <ResourceDictionary>

        <!-- Styles -->
        <!-- Styles -->

    </ResourceDictionary>

</Application.Resources>

單擊ContentPage按鈕中的代碼

Application.Current.Resources.Add(new Xamarin.Forms.Style(typeof(ContentPage))
            {
                ApplyToDerivedTypes = true,
                Setters = {
                new Xamarin.Forms.Setter { Property = ContentPage.BackgroundImageProperty, Value = "Assets/bkg8.png"},
            }
            });

該代碼可以正常工作,但是當前樣式無法將其自身保存在App.xaml中。 我希望每次應用啟動時都保存並加載它。

謝謝。

您可以使用Xamarin屬性存儲來存儲您的寶貴資產,然后在下次啟動時更改資源。

https://docs.microsoft.com/zh-cn/xamarin/xamarin-forms/app-fundamentals/application-class#properties-dictionary

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM