想用ControlTemplate重写button的显示,让一个button上显示一张图片。
这样写没有问题:
<Button x:Name="image_Button" Width="50" Height="50">
<Grid>
<Image>
<Image.Source>
<BitmapImage UriSource="./Resources/image/player_play.png"/>
</Image.Source>
</Image>
</Grid>
</Button>但是用ControlTemplate就不可以:
<Button x:Name="image_Button" Width="50" Height="50">
<Button.Template>
<ControlTemplate>
<Grid>
<Image>
<Image.Source>
<BitmapImage UriSource="./Resources/image/player_play.png"/>
</Image.Source>
</Image>
</Grid>
</ControlTemplate>
</Button.Template>
</Button>
请求高数指点。
这样写没有问题:
<Button x:Name="image_Button" Width="50" Height="50">
<Grid>
<Image>
<Image.Source>
<BitmapImage UriSource="./Resources/image/player_play.png"/>
</Image.Source>
</Image>
</Grid>
</Button>但是用ControlTemplate就不可以:
<Button x:Name="image_Button" Width="50" Height="50">
<Button.Template>
<ControlTemplate>
<Grid>
<Image>
<Image.Source>
<BitmapImage UriSource="./Resources/image/player_play.png"/>
</Image.Source>
</Image>
</Grid>
</ControlTemplate>
</Button.Template>
</Button>
请求高数指点。
解决方案 »
- The breakpoint will not currently be hit. No symbols have been loaded for this d
- using语句用法
- 请问C#如何输入和输出控制台程序的结果呢?谢谢~
- 设计时如何解决Panel遮挡问题?
- 询问asp.net中各种身份认证方法,询问asp.net中各种身份认证方法
- dataGrid设置问题!
- 这样有错吗,我不明白?111111111
- === 自定义控件的事件处理问题 (请saucer(思归)、Eddie005(暴走005)以及各位老大帮助)===
- .NET设计中是如何实现数据、显示分层的?
- 请教:关于DataSet.WriteXml()方法得到的结果的根元素名字总是<NewDataSet>怎么把它改掉?
- 请问,这个正则表达式该怎么写?
- 怎么用递归绑定数据
要么为相对路径,要么为绝对路径
如果player_play.png在项目解决方案下的文件夹下可以这么写:
UriSource="Resources/image/player_play.png"
<Image x:Name="IconImage" Source="/TestPro;component/Images/computer2.png" Height="15" Width="15" />
同样的路径放在grid中就没有问题。
我测试了下 如果相对路径 在里面写成./也是没有问题的 可以显示成功
我发的那个绝对路径也是可以跑的
个人建议写成这样 TestPro是project的名称 Images/computer2.png是文件相对根目录的路径
/TestPro;component/Images/computer2.png所以基本上都是没有问题的 代码不用贴了 楼主如果真的想搞明白就把你代码贴出来我看看吧
不然我也不知道怎么给你找错哦
WpfApplication2
->Resources
-->image
--->player_play.png
<Button x:Name="image_Button" Width="50" Height="50">
<!--<Grid>
<Image Source="{StaticResource Image_player_play}">
</Image>
</Grid>-->
<Button.Template>
<ControlTemplate >
<Grid> <Image Source="/Resources/image/player_play.png">
</Image>
</Grid>
</ControlTemplate>
</Button.Template>
</Button>
用了你的代码我测试没有问题啊 显示正常啊
或者你仔细看下报错吧 也许不是control template的问题哦 呵呵
我也重新试了下,
原来是用了controltemplate以后button变成没有任何效果的了,
再加上图片也是有透明效果的白色图片,
所以不是代码的问题,是显示出来了,没看出来。
把button的背景设置成black就可以了。
非常感谢!