如何从代码隐藏中替换Pivot应用程序背景?

3 c# silverlight xaml windows-phone-7

我在Pivot中使用自定义背景图像(不是全景)应用程序:

<controls:Pivot Title="My Application">
<controls:Pivot.Background>
    <ImageBrush ImageSource="Theme1.png" Stretch="Fill"/>
</controls:Pivot.Background>
Run Code Online (Sandbox Code Playgroud)

它工作正常,但我想在运行时替换图像.可能吗?

key*_*rdP 7

你可以给你ImageBrush一个名字:

<ImageBrush x:Name="ibPivot" ImageSource="Theme1.png" Stretch="Fill"/>
Run Code Online (Sandbox Code Playgroud)

然后在代码隐藏中更改源代码:

BitmapImage bi = new BitmapImage(new Uri("mySecondImage.png", UriKind.Relative));
ibPivot.ImageSource = bi;
Run Code Online (Sandbox Code Playgroud)