问题1
如何在不删除整个画布内容的情况下覆盖书面文本? 我可以通过C#做到这一点吗? 没有在XAML代码中添加元素?
问题2
我集成了一个缩放功能,但只有在我指向画布上绘制的东西时它才会缩放。 当我只是指向我的Canvas时,我怎么才能缩放?
XAML
<Canvas x:Name="coordinateSystemBackground" VerticalAlignment="Top" Cursor="Cross" MouseWheel="coordinateSystemBackground_MouseWheel" RenderTransformOrigin="0.688,0.559" Width="1200" Height="720"> <ScrollViewer Grid.Column="0" Grid.Row="0" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Width="1200" Height="750"> <Canvas x:Name="coordinateSystem" HorizontalAlignment="Left" VerticalAlignment="Top" Cursor="Cross" UseLayoutRounding="False" Canvas.Left="0" Width="1200" Height="720"> <Canvas.RenderTransform> <ScaleTransform x:Name="st"/> </Canvas.RenderTransform> </Canvas> </ScrollViewer> </Canvas>My Zoom function
private void coordinateSystemBackground_MouseWheel(object sender, MouseWheelEventArgs e) { // Skalierungsfaktor double ScaleRate = 1.1; //Transformiert gesamte Canvas... if (e.Delta > 0) { st.ScaleX *= ScaleRate; st.ScaleY *= ScaleRate; labZoomFaktor.Content = (int)((st.ScaleX * 100) - 100) + " %"; } else { st.ScaleX /= ScaleRate; st.ScaleY /= ScaleRate; labZoomFaktor.Content = (int)((st.ScaleX * 100) - 100) + " %"; } }Problem 1
How can I override a written text without delete the whole canvas content? Can I do that over C#? Without adding elements in the XAML code?
Problem 2
I intergrated a zoom function but it zooms only if I'm pointing on something drawn in my canvas. How can I just zoom when I'm just pointing on my Canvas?
XAML
<Canvas x:Name="coordinateSystemBackground" VerticalAlignment="Top" Cursor="Cross" MouseWheel="coordinateSystemBackground_MouseWheel" RenderTransformOrigin="0.688,0.559" Width="1200" Height="720"> <ScrollViewer Grid.Column="0" Grid.Row="0" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Width="1200" Height="750"> <Canvas x:Name="coordinateSystem" HorizontalAlignment="Left" VerticalAlignment="Top" Cursor="Cross" UseLayoutRounding="False" Canvas.Left="0" Width="1200" Height="720"> <Canvas.RenderTransform> <ScaleTransform x:Name="st"/> </Canvas.RenderTransform> </Canvas> </ScrollViewer> </Canvas>My Zoom function
private void coordinateSystemBackground_MouseWheel(object sender, MouseWheelEventArgs e) { // Skalierungsfaktor double ScaleRate = 1.1; //Transformiert gesamte Canvas... if (e.Delta > 0) { st.ScaleX *= ScaleRate; st.ScaleY *= ScaleRate; labZoomFaktor.Content = (int)((st.ScaleX * 100) - 100) + " %"; } else { st.ScaleX /= ScaleRate; st.ScaleY /= ScaleRate; labZoomFaktor.Content = (int)((st.ScaleX * 100) - 100) + " %"; } }最满意答案
为了使命中测试获取鼠标输入,需要在光标下有一些非空的目标元素部分。 在这种情况下,画布的子项正在拾取事件并将它们冒泡到Canvas但Canvas本身只是空白空间,因此不会拾取鼠标输入。 通过在Canvas上设置Background="Transparent" ,您将使整个事物可见以进行测试。
In order for hit testing to pick up mouse input there needs to be some non-null part of the targeted element under the cursor. In this case the canvas's children are picking up events and bubbling them to the Canvas but the Canvas itself is just empty space and so won't pick up the mouse input. By setting Background="Transparent" on the Canvas you will make the entire thing visible to hit testing.
更多推荐
发布评论