WP7中Button的Image背景图片路径获取

<Button  Grid.Row="1" Height="201" HorizontalAlignment="Left" Margin="198,13,0,0" Name="button3"      
                        VerticalAlignment="Top" Width="215" Grid.ColumnSpan="2"  BorderThickness="0" Click="button3_Click">
                    <Button.Background>
                        <ImageBrush ImageSource="/MyHometown;component/photos/4.jpg" Stretch="Fill" />
                    </Button.Background>
                </Button>


获得背景图片地址,然后在其他页面使用。

private void button1_Click(object sender, RoutedEventArgs e)
        {
            ImageBrush i = button1.Background as ImageBrush; //background属性是Brush类 转换成ImageBrush因为图片的ImageSource是ImageBrush类。。。
        BitmapImage ii = i.ImageSource as BitmapImage; // BitmapImage类中有UriSource属性,该属性就是图片的相对地址,而ImageBrush的ImageSource属性是父类是BitmapImage,转换一下就OK
            txtText.Text = ii.UriSource.ToString(); //得到图片地址,或保存在变量中
        }


原问题链接:http://bbs.itheima.com/forum.php?mod=viewthread&tid=7846&highlight=

转载于:https://www.cnblogs.com/ouyating/archive/2012/04/05/2433925.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值