如何更改CustomControl的ImageSource [英] How to change the ImageSource of CustomControl

查看:68
本文介绍了如何更改CustomControl的ImageSource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

II具有一个自定义控件,其中包含一个ImageButton.

代码如下:

              <MyDropDownButton:ImageButton
                    MinHeight="{TemplateBinding MinimalDefaultImageHeight}"
                    MinWidth="{TemplateBinding MinimalDefaultImageWidth}"
                    x:Name="PART_DEFAULTIMAGE" Grid.Column="0"
                    Command="{Binding Path=DefaultCommand,Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}"
                    Source="{Binding Path=DefaultButtonImage,Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" >
</MyDropDownButton>

当我尝试更改Source(图像源对象)时,它无效.

我已经独立测试过图像按钮,它可以正常工作.

所以在customcontrol中使用时有什么问题?

谢谢.


击败Microsoft.

解决方案

自定义ImageButton是从Button扩展的吗?原因我不知道wpf中任何名为" http://msdn.microsoft.com/en-us/library/cc295235.aspx

好运


II've a custom control which has a ImageButton in it .

Code looks like below :

              <MyDropDownButton:ImageButton
                    MinHeight="{TemplateBinding MinimalDefaultImageHeight}"
                    MinWidth="{TemplateBinding MinimalDefaultImageWidth}"
                    x:Name="PART_DEFAULTIMAGE" Grid.Column="0"
                    Command="{Binding Path=DefaultCommand,Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}"
                    Source="{Binding Path=DefaultButtonImage,Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" >
</MyDropDownButton>

When I try to change the Source (a imagesource object) , it has no effect .

I've test the image button standalone , it works fine .

So  what's the problem with it when used in customcontrol ???

Thanks .


Beat Microsoft.

解决方案

Hi,

Is the custom ImageButton is extend from Button? Cause I dont know of any Buildin control in wpf named as "ImageButton". Is the ImageSource is a dependency property. Try Making it a dependency property. 

http://msdn.microsoft.com/en-us/library/cc295235.aspx

Best of Luck


这篇关于如何更改CustomControl的ImageSource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆