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

リソースで 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 に答える