[英]Magnifing glass in WPF
How can I create a non-circular magnifying glass in WPF? 如何在WPF中创建非圆形放大镜? This has to work on controls not just an image.
这必须在控件上工作,而不仅仅是图像。 Every example I find online is either circular only or only works on images.
我在网上找到的每个例子都是圆形或仅适用于图像。
For example I have a slider, and I'd like to turn the thumb into a rectangular magnifying region to show enlarged ticks (as my ticks are displayed in the Slider track itself, not below it). 例如,我有一个滑块,我想将拇指变成一个矩形放大区域以显示放大的刻度(因为我的刻度显示在Slider轨道本身,而不是它下面)。 I have created all the styles necessary I am just missing the ability to magnify contents underneath the thumb (as the thumb sits on top of the controls / display)
我已经创建了所有必需的样式我只是缺少放大拇指下方内容的能力(因为拇指位于控件/显示器的顶部)
<Slider Ticks="{Binding MyCollection}" />
Thanks 谢谢
It's pretty easy to just make your own 'magnifying' control. 只做自己的'放大'控制很容易。 You could use a
VisualBrush
with a Visual
property taken from the source (that you want to magnify) painted onto a plain Rectangle
. 您可以使用
VisualBrush
将Visual
属性从源(要放大)绘制到一个普通的Rectangle
。 See the Using VisualBrush to Show a Magnifying Glass page on the Ian G on Tap website as an example. 有关示例,请参阅Ian G on Tap网站上的使用VisualBrush显示放大镜页面。
Better yet, here is a very simple example of a VisualBrush
that is painting a Rectangle
in the right column of a Grid
, magnifying an Image
from the left column of a Grid
. 更重要的是,这里是一个非常简单的例子
VisualBrush
是画一个Rectangle
中的右列Grid
,放大的Image
从左栏Grid
。 You can tweak it to your liking: 你可以根据自己的喜好调整它:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Image Name="Image" Source="Images/BlackLogo.ico" Width="150" Height="150" />
<Rectangle Grid.Column="1">
<Rectangle.Fill>
<VisualBrush Visual="{Binding ., ElementName=Image}"
Viewport="50,100,300,300" ViewportUnits="Absolute" />
</Rectangle.Fill>
</Rectangle>
</Grid>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.