我想实现一个userControl,它能够使用提供的鼠标输入进行滚动和缩放。
因此,我实现了以下用户控件。 (如果它正在工作我将把事件直接移到模型中)
ScrollDragZoomControl.xaml
<UserControl x:Class="MinimalMonitoringClient.Controls.ScrollDragZoomControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:models="clr-namespace:MinimalMonitoringClient.Controls.Models"
Background="Transparent">
<UserControl.DataContext>
<models:ScrollDragZoomViewModel />
</UserControl.DataContext>
<ScrollViewer x:Name="scrollViewer"
MouseLeftButtonUp="scrollViewer_MouseLeftButtonUp"
PreviewMouseLeftButtonUp="scrollViewer_PreviewMouseLeftButtonUp"
PreviewMouseWheel="scrollViewer_PreviewMouseWheel"
PreviewMouseLeftButtonDown="scrollViewer_PreviewMouseLeftButtonDown"
MouseMove="scrollViewer_MouseMove"
VerticalScrollBarVisibility="{Binding VerticalScrollBarVisibility}"
HorizontalScrollBarVisibility="{Binding HorizontalScrollBarVisibility}">
<Grid RenderTransformOrigin="0.5,0.5">
<Grid.LayoutTransform>
<TransformGroup>
<ScaleTransform />
</TransformGroup>
</Grid.LayoutTransform>
<Viewbox>
<!-- Present the actual stuff the user wants to display -->
<ContentPresenter />
</Viewbox>
</Grid>
</ScrollViewer>
在另一个UserControl中,我想使用此UserControl,以显示可能比当前UserControl的宽度和高度更大的内容。对于测试,我将宽度和高度设置为巨大的值。
<UserControl x:Class="MinimalMonitoringClient.Panels.HierarchicalView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:panels="clr-namespace:MinimalMonitoringClient.Models.Panels"
xmlns:controls="clr-namespace:MinimalMonitoringClient.Controls">
<UserControl.DataContext>
<panels:HierarchicalViewModel />
</UserControl.DataContext>
<controls:ScrollDragZoomControl>
<Image Source="/Images/Information.png" Width="2000" Height="2000" IsHitTestVisible="False" />
</controls:ScrollDragZoomControl>
答案 0 :(得分:2)
当您将Content
的{{1}}属性设置为UserControl
元素时,您实际上会“覆盖”您在Image
中定义的所有内容。
您可能希望ScrollDragZoomControl.xaml
以及您在ScrollViewer
中定义的其他内容成为UserControl的模板的一部分:
ScrollDragZoomControl.xaml