0

我想动态更改我的 longlistselector 的跳转列表的颜色。我在 xaml 中定义了 JumpListBackgroundCONverter,如下所示

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

在 C# 中,组件初始化后 BackgroundConvert 返回 null

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

我将启用的值更改为新画笔,并计划在整个代码中更改它。由于某种原因,它返回 null 并崩溃。

在 InitializeComponent 我想 FindName 返回 null 但我不知道为什么

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

顺便说一句,这是适用于 windows phone 8 的!

4

1 回答 1

1

你只需要在 resources 中使用 x:key,你不需要使用 x:Name="BackgroundConvert"。

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

然后,您可以使用它x:Key="BackgroundConverter" 在后面代码中的值从资源中访问它。资源是一个字典。

var converter = (Microsoft.Phone.Controls.JumpListItemBackgroundConverter)this.Resources["BackgroundConverter"];
于 2013-12-25T09:06:32.867 回答