询问者
WPF 如何制作按九宫格拉伸的画刷?

问题
全部回复
-
你好,
我们不可以制作自定义的画刷(通过从Brush类继承),因为Brush类和衍生类都是abstract或者sealed。
对于你的需求,可以使用VisualBrush(http://msdn.microsoft.com/en-us/library/system.windows.media.visualbrush(v=vs.110).aspx),配合Viewport属性:
<Window.Resources> <VisualBrush x:Key="MyBrush" Viewport="10, 10, 100, 60" ViewportUnits="Absolute"> <VisualBrush.Visual> <Image Source="avatar.png" /> </VisualBrush.Visual> </VisualBrush> </Window.Resources> <Grid> <Button Width="120" Height="80" Background="{StaticResource MyBrush}" /> </Grid>
截图:
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已编辑 Franklin ChenMicrosoft employee, Moderator 2014年3月10日 2:54
- 已标记为答案 Franklin ChenMicrosoft employee, Moderator 2014年3月14日 10:12
- 取消答案标记 Franklin ChenMicrosoft employee, Moderator 2014年3月19日 3:00
-
举个例子就是button放大缩小时,周围的圆角的大小是要保持原尺寸的,但我用一整张图来呈现button的外观,这就要求这张图的button的圆角部分是不能拉伸的,但中间区域应该拉伸。
你给出的这个例子是把一幅图均匀缩放到空间中,图的周围有固定长度的空白边距。我想要的是图本身就把控件充满,但是并非均匀缩放,而是图有一部分保持原比例,具体方式如下图:(我用你的图,我按照自己的要求重新用画图程序修改了一下)
DrawingBrash,VisualBrash我都考虑过。viewport和viewbox我都看了效果。遇到的问题是,如果绝对值和相对值不能同时使用,我就无法做出想要的效果。
-
你好,
据我所知,加上各种尝试,应该是没有办法很方便地去实现你要的需求,但是我有一个觉得可能的解决方案:
对背景图片进行切分,然后自定义Button 模板,由9部分组成,分别用不同的拉伸方式进行填充,这样应该可以实现你要的效果。
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey. -
你好,
据我所知,可能没有简单易行的方法了,可能一些封装好的三方控件实现了此功能,你可以搜索下:)
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.