Zoom Control 是 Codeplex 上可用的 WPF 扩展的一部分
我想在 http://wpfextensions.codeplex.com/ 中找到缩放控件我的项目。然而,有一个功能我希望它具有。我希望它与 ScrollViewer 一起使用,这样如果内容放大,滚动条就会激活(如果需要)。
控件的模板在 Generic.xaml 中定义:
<Style TargetType="{x:Type Controls:ZoomControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Controls:ZoomControl}">
<Grid>
<Border BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="Green"
ClipToBounds="{TemplateBinding ClipToBounds}">
<Controls:ZoomContentPresenter x:Name="PART_Presenter"
ClipToBounds="False" />
</Border>
<Canvas>
<!-- Controls -->
<Border Padding="5"
CornerRadius="5"
Background="#88C0C0C0"
Canvas.Left="20"
Canvas.Top="20"
ToolTipService.InitialShowDelay="0">
<Border.ToolTip>
<StackPanel Orientation="Vertical">
<TextBlock><Run FontWeight="Bold">CTRL + Wheel:</Run> Zoom In / Out</TextBlock>
<TextBlock><Run FontWeight="Bold">ALT + Drag:</Run> ZoomBox</TextBlock>
<TextBlock><Run FontWeight="Bold">(SHIFT +) Drag:</Run> Pan</TextBlock>
</StackPanel>
</Border.ToolTip>
<StackPanel Orientation="Vertical">
<StackPanel.Resources>
<Style TargetType="{x:Type RadioButton}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RadioButton}">
<Border x:Name="border"
BorderBrush="Black"
Background="Silver"
BorderThickness="1"
CornerRadius="5"
Width="40"
Height="40"
Margin="2"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver"
Value="True">
<Setter TargetName="border"
Property="Background"
Value="WhiteSmoke" />
</Trigger>
<Trigger Property="IsChecked"
Value="True">
<Setter TargetName="border"
Property="Background"
Value="DarkGray" />
<Setter TargetName="border"
Property="TextBlock.FontWeight"
Value="Bold" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</StackPanel.Resources>
<Slider Height="150"
Minimum="{TemplateBinding MinZoom,Converter={StaticResource log10Converter}}"
Maximum="{TemplateBinding MaxZoom,Converter={StaticResource log10Converter}}"
Value="{Binding RelativeSource={RelativeSource TemplatedParent},Path=Zoom,Mode=TwoWay,Converter={StaticResource log10Converter}}"
HorizontalAlignment="Center"
Ticks="0.1, 0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 2"
AutoToolTipPlacement="BottomRight"
AutoToolTipPrecision="1"
TickPlacement="BottomRight"
TickFrequency="1"
LargeChange="1"
SmallChange="0.1"
Orientation="Vertical" />
<TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent},Path=Zoom,StringFormat='{}{0:F2}x'}"
HorizontalAlignment="Center"
FontWeight="Bold" />
<RadioButton Content="1:1"
GroupName="rbgZoomMode"
IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent},Path=Mode,Converter={StaticResource equalityConverter},ConverterParameter={x:Static Controls:ZoomControlModes.Original}}" />
<RadioButton Content="Fill"
GroupName="rbgZoomMode"
IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent},Path=Mode,Converter={StaticResource equalityConverter},ConverterParameter={x:Static Controls:ZoomControlModes.Fill}}" />
</StackPanel>
</Border>
<!-- ZoomBox -->
<Border BorderBrush="{TemplateBinding ZoomBoxBorderBrush}"
BorderThickness="{TemplateBinding ZoomBoxBorderThickness}"
Canvas.Left="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ZoomBox.X}"
Canvas.Top="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ZoomBox.Y}"
Opacity="{TemplateBinding ZoomBoxOpacity}"
Background="{TemplateBinding ZoomBoxBackground}"
Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ZoomBox.Width}"
Height="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ZoomBox.Height}" />
</Canvas>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Background"
Value="White" />
<Setter Property="ZoomBoxBackground">
<Setter.Value>
<LinearGradientBrush StartPoint="0.0, 0.0"
EndPoint="1.0, 1.0">
<GradientStop Color="Silver"
Offset="0.0" />
<GradientStop Color="DarkGray"
Offset="1.0" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter Property="ZoomBoxBorderBrush"
Value="Black" />
<Setter Property="ZoomBoxBorderThickness"
Value="1" />
<Setter Property="ClipToBounds"
Value="True" />
<Style.Triggers>
<Trigger Property="ModifierMode"
Value="Pan">
<Setter Property="Cursor"
Value="SizeAll" />
</Trigger>
<Trigger Property="ModifierMode"
Value="ZoomBox">
<Setter Property="Cursor"
Value="Hand" />
</Trigger>
</Style.Triggers>
</Style>
我尝试在 PART_Presenter 周围添加 ScrollViewer 标记,但这导致控件中断(没有呈现任何内容)。
希望比我聪明的人可以帮助我解决这个问题。该控件并不复杂,但我仍在学习 WPF,尤其是模板。
多谢。
The zoom control found at http://wpfextensions.codeplex.com/ is something that I would like to use in my project. However, there is one feature I wish it had. I would like for it to work with a ScrollViewer so that if the contents are zoomed in, the scrollbars would activate (if necessary).
The control's template is defined in Generic.xaml:
<Style TargetType="{x:Type Controls:ZoomControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Controls:ZoomControl}">
<Grid>
<Border BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="Green"
ClipToBounds="{TemplateBinding ClipToBounds}">
<Controls:ZoomContentPresenter x:Name="PART_Presenter"
ClipToBounds="False" />
</Border>
<Canvas>
<!-- Controls -->
<Border Padding="5"
CornerRadius="5"
Background="#88C0C0C0"
Canvas.Left="20"
Canvas.Top="20"
ToolTipService.InitialShowDelay="0">
<Border.ToolTip>
<StackPanel Orientation="Vertical">
<TextBlock><Run FontWeight="Bold">CTRL + Wheel:</Run> Zoom In / Out</TextBlock>
<TextBlock><Run FontWeight="Bold">ALT + Drag:</Run> ZoomBox</TextBlock>
<TextBlock><Run FontWeight="Bold">(SHIFT +) Drag:</Run> Pan</TextBlock>
</StackPanel>
</Border.ToolTip>
<StackPanel Orientation="Vertical">
<StackPanel.Resources>
<Style TargetType="{x:Type RadioButton}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RadioButton}">
<Border x:Name="border"
BorderBrush="Black"
Background="Silver"
BorderThickness="1"
CornerRadius="5"
Width="40"
Height="40"
Margin="2"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver"
Value="True">
<Setter TargetName="border"
Property="Background"
Value="WhiteSmoke" />
</Trigger>
<Trigger Property="IsChecked"
Value="True">
<Setter TargetName="border"
Property="Background"
Value="DarkGray" />
<Setter TargetName="border"
Property="TextBlock.FontWeight"
Value="Bold" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</StackPanel.Resources>
<Slider Height="150"
Minimum="{TemplateBinding MinZoom,Converter={StaticResource log10Converter}}"
Maximum="{TemplateBinding MaxZoom,Converter={StaticResource log10Converter}}"
Value="{Binding RelativeSource={RelativeSource TemplatedParent},Path=Zoom,Mode=TwoWay,Converter={StaticResource log10Converter}}"
HorizontalAlignment="Center"
Ticks="0.1, 0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 2"
AutoToolTipPlacement="BottomRight"
AutoToolTipPrecision="1"
TickPlacement="BottomRight"
TickFrequency="1"
LargeChange="1"
SmallChange="0.1"
Orientation="Vertical" />
<TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent},Path=Zoom,StringFormat='{}{0:F2}x'}"
HorizontalAlignment="Center"
FontWeight="Bold" />
<RadioButton Content="1:1"
GroupName="rbgZoomMode"
IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent},Path=Mode,Converter={StaticResource equalityConverter},ConverterParameter={x:Static Controls:ZoomControlModes.Original}}" />
<RadioButton Content="Fill"
GroupName="rbgZoomMode"
IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent},Path=Mode,Converter={StaticResource equalityConverter},ConverterParameter={x:Static Controls:ZoomControlModes.Fill}}" />
</StackPanel>
</Border>
<!-- ZoomBox -->
<Border BorderBrush="{TemplateBinding ZoomBoxBorderBrush}"
BorderThickness="{TemplateBinding ZoomBoxBorderThickness}"
Canvas.Left="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ZoomBox.X}"
Canvas.Top="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ZoomBox.Y}"
Opacity="{TemplateBinding ZoomBoxOpacity}"
Background="{TemplateBinding ZoomBoxBackground}"
Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ZoomBox.Width}"
Height="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ZoomBox.Height}" />
</Canvas>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Background"
Value="White" />
<Setter Property="ZoomBoxBackground">
<Setter.Value>
<LinearGradientBrush StartPoint="0.0, 0.0"
EndPoint="1.0, 1.0">
<GradientStop Color="Silver"
Offset="0.0" />
<GradientStop Color="DarkGray"
Offset="1.0" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter Property="ZoomBoxBorderBrush"
Value="Black" />
<Setter Property="ZoomBoxBorderThickness"
Value="1" />
<Setter Property="ClipToBounds"
Value="True" />
<Style.Triggers>
<Trigger Property="ModifierMode"
Value="Pan">
<Setter Property="Cursor"
Value="SizeAll" />
</Trigger>
<Trigger Property="ModifierMode"
Value="ZoomBox">
<Setter Property="Cursor"
Value="Hand" />
</Trigger>
</Style.Triggers>
</Style>
I tried adding ScrollViewer tags around the PART_Presenter but that caused the control to break (nothing was rendered).
Hopefully someone smarter than I am can help me out with this. The control is not that complex but I am still learning WPF and especially templating.
Thanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终选择了另一条路线,并使用缩放控件平移功能进行轻微修改,而不是尝试添加滚动条。
I ended up going another route and using the zoom controls panning feature with slight modifications instead of trying to add scrollbars.