Frage

I want to dynamically change the colour of my Jump List of my longlistselector. I have the JumpListBackgroundCOnverter defined in the xaml as below in the resources

<phone:PhoneApplicationPage.Resources>
<phone:JumpListItemBackgroundConverter x:Name="BackgroundConvert" x:Key="BackgroundConverter" Enabled="#FFA20025"/>

In C# after the components are initialized BackgroundConvert returns null

    public MainPage()
    {
        InitializeComponent();
        this.BackgroundConvert.Enabled = new SolidColorBrush(ThemeGradient.Color);

I change the enabled value to a new brush, and plan to change it throughout the code. For some reason it returns null and crashes.

In InitializeComponent I suppose FindName returns null but I cannot figure out why

     this.BackgroundConvert = ((Microsoft.Phone.Controls.JumpListItemBackgroundConverter)(this.FindName("BackgroundConvert")));

Btw, this is for windows phone 8!

War es hilfreich?

Lösung

You only need to use x:key in resources , You don't need to use x:Name="BackgroundConvert".

<phone:JumpListItemBackgroundConverter x:Key="BackgroundConverter" Enabled="#FFA20025"/>

Then you can access it from Resources using it's x:Key="BackgroundConverter" value in your code behind. Resources is a Dictionary.

var converter = (Microsoft.Phone.Controls.JumpListItemBackgroundConverter)this.Resources["BackgroundConverter"];
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top