Windows Phone 7.1应用程序中的动态更改图像源

时间:2012-01-08 19:34:19

标签: windows-phone-7

我的应用中有一个列表框,列表框中有一个按钮。我将图像应用于该按钮(appbar.edit.rest.png图标)。但是当主题变为灯光时,图标不会显示...当主题发生变化时,我该如何动态更改该图标。 Xaml代码如下:

<ListBox x:Name="passwordSaferRecordsListBox" ItemsSource="{Binding EntityRecordInfoItems}" Grid.Row="0" Margin="12, 140, 0, 0" FontSize="40" HorizontalAlignment="Center" >    

<ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid HorizontalAlignment="Stretch" Width="440">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <TextBlock
                            Text="{Binding RecordName}"
                            FontSize="{StaticResource PhoneFontSizeLarge}"
                            Grid.Column="0"
                            VerticalAlignment="Center"/>
                        <Button
                            Grid.Column="1"
                            x:Name="editTaskButton"
                            BorderThickness="0"                                
                            Margin="0"
                            Click="editTaskButton_Click" DataContext="{Binding}">
                            <Image Source="appbar.edit.rest.png"></Image>
                        </Button>
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

1 个答案:

答案 0 :(得分:0)

您可以将viewmodel与ImageUri一起使用:

private Uri imageUrl;

    public Uri ImageUrl
    {
        get { return imageUrl; }

        set
        {
            if (imageUrl != value)
            {
                imageUrl = value;
                RaisePropertyChanged("ImageUrl");
            }
        }
    }

然后你去你的XAML并绑定图像:

<Image  x:Name="BackgroundImage"  Height="50" Width="50" Stretch="Fill">
  <Image.Source>
       <BitmapImage UriSource="{Binding Path=ImageUrl,Mode=TwoWay}" />
  </Image.Source>
</Image>

我希望这会对你有所帮助!

相关问题