[英]Get button sender ImageBrush.ImageSource from XAML
First of all I have multiple buttons that Send me to another page and I want that on second page to show ImageBrush
of this Button. 首先,我有多个将我发送到另一页的按钮,我希望第二页上显示该按钮的
ImageBrush
。 Fields like x:Name
, Tag
and Content
are already busy so I can't use them. x:Name
, Tag
和Content
类的字段已经很忙,因此我无法使用它们。 My buttons are like this: 我的按钮是这样的:
XAML XAML
<Button x:Name="but01" Click="Button2_Click" Tag="this tag is bussy" Content="First Button" >
<Button.Background>
<ImageBrush x:Name="brush1" ImageSource="/Assets/Logos/1.png" Stretch="Uniform" />
</Button.Background>
</Button>
Code behind: 后面的代码:
private void Button2_Click(object sender, EventArgs e)
{
//this is what I've tried
var brush = new ImageBrush();
brush = (ImageBrush)((sender as Button).Background);
string mynew = brush.ImageSource.ToString();
NavigationService.Navigate(
new Uri("/MainPage.xaml?path=" +
HttpUtility.UrlEncode((sender as Button).Tag.ToString())+ "&source="+ mynew,
UriKind.Relative));
}
Where mynew = System.Windows.Media.Imaging.BitmapImage
and I want it to be: /Assets/Logos/1.png
其中
mynew = System.Windows.Media.Imaging.BitmapImage
,我希望它是: /Assets/Logos/1.png
Any ideas? 有任何想法吗? Maybe there is other fields where I can store this path except
Tag
, Name
and Content
? 也许还有其他字段可以存储此路径,但“
Tag
,“ Name
和“ Content
除外?
You should use BitmapImage instead of ImageSource . 您应该使用BitmapImage而不是ImageSource 。
You can get the image path like this: 您可以这样获得图像路径:
var brush = but01.Background as ImageBrush;
BitmapImage source = brush.ImageSource as BitmapImage;
Uri uri = source.UriSource;
string uriStr = uri.OriginalString;
the field uriStr is the value you want ! uriStr字段是您想要的值!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.