Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ZoomContentControl as a stand alone control in Toolkit (backport #1249) #1270

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a20cf9d
feat: ZoomContentControl is a stand alone control in Toolkit now
vatsashah45 Sep 18, 2024
4deaf4d
feat: ZoomContentControl Sample
vatsashah45 Sep 19, 2024
3d361bd
fix: ZoomContentControl Sample
vatsashah45 Sep 23, 2024
3370175
docs: ZoomContentControl
vatsashah45 Sep 23, 2024
a4a3fda
fix: ZoomContentControl Sample
vatsashah45 Sep 24, 2024
2bc8125
chore: resolving comments
vatsashah45 Sep 24, 2024
8ffb10d
chore: misc changes
vatsashah45 Sep 24, 2024
7976ba2
chore: renaming zoomcontentcontrol
vatsashah45 Sep 24, 2024
c59eac6
chore: formatting docs
vatsashah45 Sep 25, 2024
053a52a
chore: ZoomContentControl Tests
vatsashah45 Sep 25, 2024
de03df7
chore: resolving comments
vatsashah45 Sep 27, 2024
580dda3
chore: resolving comments
vatsashah45 Sep 27, 2024
6d4df91
chore: refactor properties into separate file
Xiaoy312 Oct 3, 2024
3afeba9
chore: refactor ZoomContentControl.cs
vatsashah45 Oct 4, 2024
08fcc6c
fix: ci build
vatsashah45 Oct 4, 2024
c0be4ec
chore: refactor
Xiaoy312 Oct 10, 2024
4e26756
chore: refactor
vatsashah45 Oct 10, 2024
2802fac
chore: xml comments for HorizontalScrollValue
vatsashah45 Oct 10, 2024
60b366d
chore: removed VerticalScrollValue
vatsashah45 Oct 13, 2024
96ff5f4
fix: VerticalScrollValue and tests
vatsashah45 Oct 14, 2024
27d3c55
chore: resolving comments
vatsashah45 Oct 14, 2024
00baadc
chore: resolving comments
vatsashah45 Oct 15, 2024
6827bc0
chore: set default MaxZoomLevel to 10
Xiaoy312 Oct 17, 2024
d2fd32d
chore: minor refactor
Xiaoy312 Oct 17, 2024
425ef05
chore: ZoomContentControl refactor/cleanup
Xiaoy312 Oct 22, 2024
89d1084
chore: update docs and private properties
vatsashah45 Oct 22, 2024
5ca597a
fix: RaiseRenderedContentUpdated being called twice
vatsashah45 Oct 22, 2024
71832a0
chore: add mouse wheel zooming
Xiaoy312 Oct 23, 2024
a6a835c
chore: bugfixes
Xiaoy312 Oct 23, 2024
26121cf
chore: fix build
Xiaoy312 Oct 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions doc/controls/ZoomContentControl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
uid: Toolkit.Controls.ZoomContentControl
---

# ZoomContentControl

> [!TIP]
> This guide covers details for the `ZoomContentControl`. If you are just getting started with the Uno Toolkit UI Library, please see our [general getting started](../getting-started.md) page to make sure you have the correct setup in place.

## Summary

`ZoomContentControl` allows you to display content that can be zoomed in and out, as well as panned. It is especially useful for scenarios such as viewing large images, maps, or documents where users need control over zoom levels and panning.

### C\#

```csharp
public partial class ZoomContentControl : Control
```

### XAML

```xml
xmlns:utu="using:Uno.Toolkit.UI"
...

<utu:ZoomContentControl ZoomLevel="1.5"
MinZoomLevel="0.5"
MaxZoomLevel="3.0"
IsZoomAllowed="True"
IsPanAllowed="True">
<utu:ZoomContentControl.Content>
<Image Source="ms-appx:///Assets/Media/LargeMedia.svg"
Stretch="Uniform" />
</utu:ZoomContentControl.Content>
</utu:ZoomContentControl>
```

### Inheritance

`Object` &#8594; `DependencyObject` &#8594; `UIElement` &#8594; `FrameworkElement` &#8594; `Control` &#8594; `ContentControl` &#8594; `ZoomContentControl`

### Constructors

| Constructor | Description |
| ---------------------- | ------------------------------------------------------------- |
| `ZoomContentControl()` | Initializes a new instance of the `ZoomContentControl` class. |

### Properties

| Property | Type | Description |
| ------------------ | ----------- | ------------------------------------------------------------------------------------------------------ |
| `ZoomLevel` | `double` | Gets or sets the current zoom level for the content. |
| `MinZoomLevel` | `double` | Gets or sets the minimum zoom level allowed for the content. |
| `MaxZoomLevel` | `double` | Gets or sets the maximum zoom level allowed for the content. |
| `IsZoomAllowed` | `bool` | Gets or sets a value indicating whether zooming is allowed. |
| `ScaleWheelRatio` | `double` | Gets or sets the ratio for scaling zoom level when using a mouse wheel. |
| `PanWheelRatio` | `double` | Gets or sets the ratio for panning when using a mouse wheel. |
| `IsPanAllowed` | `bool` | Gets or sets a value indicating whether panning is allowed. |
| `IsActive` | `bool` | Gets or sets a value indicating whether the control is active. |
| `AutoFitToCanvas` | `bool` | Determines if the content should automatically fit into the available canvas when the control resizes. |
| `AdditionalMargin` | `Thickness` | Gets or sets additional margins around the content. |

### Methods

| Method | Return Type | Description |
| ----------------- | ----------- | ----------------------------------------------------------------------------------------- |
| `FitToCanvas()` | `void` | Adjust the zoom level so that the content fits within the available space. |
| `ResetViewport()` | `void` | Resets the zoom level and panning offset to their default values and centers the content. |
2 changes: 2 additions & 0 deletions doc/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
href: controls/ShadowContainer.md
- name: TabBar and TabBarItem
href: controls/TabBarAndTabBarItem.md
- name: ZoomContentControl
href: controls/ZoomContentControl.md
# ***************** Reference\Helpers *******************
- name: Helpers
items:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<Page x:Class="Uno.Toolkit.Samples.Content.Controls.ZoomContentControlSamplePage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Uno.Toolkit.Samples.Content.Controls"
xmlns:utu="using:Uno.Toolkit.UI"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sample="using:Uno.Toolkit.Samples"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<sample:SamplePageLayout x:Name="SamplePageLayout" IsDesignAgnostic="True">
<sample:SamplePageLayout.DesignAgnosticTemplate>
<DataTemplate>
<StackPanel>
<utu:ZoomContentControl Grid.Row="1"
x:Name="ZoomContent"
Width="400"
Height="300"
HorizontalAlignment="Center"
VerticalAlignment="Center"
ZoomLevel="1"
MinZoomLevel="0.5"
MaxZoomLevel="10"
IsZoomAllowed="True"
IsPanAllowed="True">
<Border BorderThickness="2"
BorderBrush="White"
HorizontalAlignment="Center"
Padding="10">
<Image Source="ms-appx:///Assets/UnoLogo.png"
Height="101"
Width="75"
HorizontalAlignment="Center" />
</Border>
</utu:ZoomContentControl>

<StackPanel Grid.Row="2"
Orientation="Horizontal"
Spacing="12"
HorizontalAlignment="Center"
VerticalAlignment="Bottom">
<Button x:Name="ZoomInButton" Content="Zoom In" />
<Button x:Name="ZoomOutButton" Content="Zoom Out" />
<Button x:Name="ResetButton" Content="Reset" />
</StackPanel>
</StackPanel>
</DataTemplate>
</sample:SamplePageLayout.DesignAgnosticTemplate>
</sample:SamplePageLayout>
</Grid>

</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Uno.Toolkit.Samples.Entities;
using Uno.Toolkit.UI;
using Windows.Foundation;
using Windows.Foundation.Collections;

#if IS_WINUI
using Microsoft.UI;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
#else
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
#endif


namespace Uno.Toolkit.Samples.Content.Controls;

[SamplePage(SampleCategory.Controls, "ZoomContentControl")]
public sealed partial class ZoomContentControlSamplePage : Page
{
private ZoomContentControl zoomControl;

public ZoomContentControlSamplePage()
{
this.InitializeComponent();
this.Loaded += (s, e) => SetUpOptions();
}

private void SetUpOptions()
{
zoomControl = SamplePageLayout.GetSampleChild<ZoomContentControl>(Design.Agnostic, "ZoomContent");
var zoomInButton = SamplePageLayout.GetSampleChild<Button>(Design.Agnostic, "ZoomInButton");
var zoomOutButton = SamplePageLayout.GetSampleChild<Button>(Design.Agnostic, "ZoomOutButton");
var resetButton = SamplePageLayout.GetSampleChild<Button>(Design.Agnostic, "ResetButton");

zoomInButton.Click += OnZoomInClick;
zoomOutButton.Click += OnZoomOutClick;
resetButton.Click += OnResetClick;
}

private void OnZoomInClick(object sender, RoutedEventArgs e)
{
if (zoomControl.ZoomLevel < zoomControl.MaxZoomLevel)
{
zoomControl.ZoomLevel += 0.2;
}
}

private void OnZoomOutClick(object sender, RoutedEventArgs e)
{
if (zoomControl.ZoomLevel > zoomControl.MinZoomLevel)
{
zoomControl.ZoomLevel -= 0.2;
}
}

private void OnResetClick(object sender, RoutedEventArgs e)
{
zoomControl.ResetViewport();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
<Compile Include="$(MSBuildThisFileDirectory)Content\Controls\VisualStateManagerExtensionsSamplePage.xaml.cs">
<DependentUpon>VisualStateManagerExtensionsSamplePage.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Content\Controls\ZoomContentControlSamplePage.xaml.cs">
<DependentUpon>ZoomContentControlSamplePage.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Content\Helpers\BindingExtensionsSamplePage.xaml.cs">
<DependentUpon>BindingExtensionsSamplePage.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -317,6 +320,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Content\Controls\ZoomContentControlSamplePage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Content\Helpers\BindingExtensionsSamplePage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
Loading
Loading