WPF ImageButton 问题求解
--------------------编程问答-------------------- 你可以在图片点击事件里面修改Imagebutoon的Source属性来修改图片 --------------------编程问答--------------------Source属性如何修改呢。直接用地址还是?? 我直接修改了属性。但是。运行的时候,图片就没了。显示不出来了。。。 --------------------编程问答--------------------
问题是如何修改呢,求指教。 --------------------编程问答--------------------
SOURCE值填写为URI就行了 --------------------编程问答--------------------
你可以在图片点击事件里面修改Imagebutoon的Source属性来修改图片
问题是如何修改呢,求指教。
SOURCE值填写为URI就行了
ButtonSend.Source = new BitmapImage(new Uri("Resources\\savefail.png", UriKind.Relative));
我这样使用的,但是 运行的时候,图片显示不出来是什么原因 --------------------编程问答--------------------
你可以在图片点击事件里面修改Imagebutoon的Source属性来修改图片
问题是如何修改呢,求指教。
SOURCE值填写为URI就行了
ButtonSend.Source = new BitmapImage(new Uri("Resources\\savefail.png", UriKind.Relative));
我这样使用的,但是 运行的时候,图片显示不出来是什么原因
"Resources\\savefail.png"改成@"Resources/savefail.png"试试
--------------------编程问答--------------------
你可以在图片点击事件里面修改Imagebutoon的Source属性来修改图片
问题是如何修改呢,求指教。
SOURCE值填写为URI就行了
ButtonSend.Source = new BitmapImage(new Uri("Resources\\savefail.png", UriKind.Relative));
我这样使用的,但是 运行的时候,图片显示不出来是什么原因
"Resources\\savefail.png"改成@"Resources/savefail.png"试试
还是不行,执行了这句图片就不显示了。 --------------------编程问答-------------------- 来人啊,求帮助了。 --------------------编程问答-------------------- 类似这样
this.myImage.Source = new BitmapImage(new Uri("Images/Untitled.png", UriKind.Relative));
代码没什么问题,估计是你把路径搞错了。 --------------------编程问答--------------------
类似这样
this.myImage.Source = new BitmapImage(new Uri("Images/Untitled.png", UriKind.Relative));
代码没什么问题,估计是你把路径搞错了。
路径看了下,应该也是没有什么问题的。不知道什么原因。是ImageButton 不能在代码中这样修改source吗。
--------------------编程问答-------------------- <Image VerticalAlignment="Top" Height="36" Width="36" Source="{TemplateBinding Source}"/>
Button没有ImageSource属性,你这样绑定怎么能显示,你要设一个属性,
public ImageSource ImgSource {get;set;}
然后
<Image VerticalAlignment="Top" Height="36" Width="36" Source"{Binding ImgSource, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ImageButton}}}"/>
--------------------编程问答-------------------- <Image VerticalAlignment="Top" Height="36" Width="36" Source="{Binding ImgSource, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ImageButton}}}"/> --------------------编程问答--------------------
<Image VerticalAlignment="Top" Height="36" Width="36" Source="{Binding ImgSource, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ImageButton}}}"/>
--------------------编程问答--------------------
public class ImageButton : Button
{
// Define an image button user control which is a button with image. A source (can use any name) property is defined to bind to source of inside image control
public ImageSource Source
{
get { return base.GetValue(SourceProperty) as ImageSource; }
set { base.SetValue(SourceProperty, value); }
}
public static readonly DependencyProperty SourceProperty = DependencyProperty.Register("Source", typeof(ImageSource), typeof(ImageButton));
}
<Image VerticalAlignment="Top" Height="36" Width="36" Source="{Binding ImgSource, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ImageButton}}}"/>
不太懂你的意思啊。 --------------------编程问答-------------------- Source="{TemplateBinding Source}你这个无效的绑定,Button本身没有Source属性,在模板里不能用TemplateBinding 来绑定
用Source="{Binding Source, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ImageButton}}}" 来绑定 --------------------编程问答-------------------- <Image VerticalAlignment="Top" Height="36" Width="36" Source="{TemplateBinding Source}"/>
看到这句代码没有,绑定到了Source属性,代码中修改Source属性的时候,实际上就是这个图片控件在变化 --------------------编程问答--------------------
<Image VerticalAlignment="Top" Height="36" Width="36" Source="{TemplateBinding Source}"/>
看到这句代码没有,绑定到了Source属性,代码中修改Source属性的时候,实际上就是这个图片控件在变化
嗯。。那为哈我那种不可以呢。 试了一下。如果图片的路径使用绝对路径的话,是可以显示的。相对路径就不对。 --------------------编程问答-------------------- 重写Button还不如直接用RibbonButton+样式
补充:.NET技术 , C#