Skip to content

Commit de5f0e0

Browse files
committed
chore: Attempt to Change Scroll Value
Issues: - Not cropping to lowest Zindex content (Grid Row 0) - ScrollBars won't work propperly
1 parent e0894af commit de5f0e0

File tree

3 files changed

+74
-68
lines changed

3 files changed

+74
-68
lines changed

UI/PhotoViewer/InteractionControls/ZoomContentControl.cs

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using Microsoft.UI.Xaml;
33
using Microsoft.UI.Xaml.Controls;
44
using Microsoft.UI.Xaml.Controls.Primitives;
5-
using Microsoft.UI.Xaml.Data;
65
using Microsoft.UI.Xaml.Input;
76
using Windows.Foundation;
87

@@ -189,9 +188,27 @@ private void RegisterPropertyHandlers()
189188

190189
RegisterPropertyChangedCallback(ZoomLevelProperty, (s, e) => { UpdateScrollLimits(); });
191190

191+
RegisterPropertyChangedCallback(HorizontalOffsetProperty, UpdateVerticalScrollBarValue);
192+
RegisterPropertyChangedCallback(VerticalOffsetProperty, UpdateHorizontalScrollBarValue);
193+
192194
RegisterPropertyChangedCallback(IsActiveProperty, IsActiveChanged);
193195
}
194196

197+
private void UpdateVerticalScrollBarValue(DependencyObject sender, DependencyProperty dp)
198+
{
199+
if (_scrollV is not null)
200+
{
201+
_scrollV.Value = VerticalOffset;
202+
}
203+
}
204+
private void UpdateHorizontalScrollBarValue(DependencyObject sender, DependencyProperty dp)
205+
{
206+
if (_scrollH is not null)
207+
{
208+
_scrollH.Value = HorizontalOffset;
209+
}
210+
}
211+
195212
private void IsActiveChanged(DependencyObject sender, DependencyProperty dp)
196213
{
197214
if (ResetWhenNotActive && !IsActive)
@@ -273,22 +290,22 @@ private void _scrollH_Scroll(object sender, ScrollEventArgs e)
273290
HorizontalOffset = e.NewValue;
274291
}
275292

276-
private void ApplyBindings()
277-
{
278-
if (_scrollV is not null)
279-
{
280-
var sVBinding = new Binding { Path = new PropertyPath("VerticalOffset"), Mode = BindingMode.TwoWay };
281-
sVBinding.Source = this;
282-
_scrollV.SetBinding(ScrollBar.ValueProperty, sVBinding);
283-
}
284-
285-
if (_scrollH is not null)
286-
{
287-
var sHBinding = new Binding { Path = new PropertyPath("HorizontalOffset"), Mode = BindingMode.TwoWay };
288-
sHBinding.Source = this;
289-
_scrollH.SetBinding(ScrollBar.ValueProperty, sHBinding);
290-
}
291-
}
293+
//private void ApplyBindings()
294+
//{
295+
// if (_scrollV is not null)
296+
// {
297+
// var sVBinding = new Binding { Path = new PropertyPath("VerticalOffset"), Mode = BindingMode.TwoWay };
298+
// sVBinding.Source = this;
299+
// _scrollV.SetBinding(ScrollBar.ValueProperty, sVBinding);
300+
// }
301+
302+
// if (_scrollH is not null)
303+
// {
304+
// var sHBinding = new Binding { Path = new PropertyPath("HorizontalOffset"), Mode = BindingMode.TwoWay };
305+
// sHBinding.Source = this;
306+
// _scrollH.SetBinding(ScrollBar.ValueProperty, sHBinding);
307+
// }
308+
//}
292309

293310

294311
private uint _capturedPointerId;

UI/PhotoViewer/InteractionControls/ZoomContentControl.xaml

Lines changed: 40 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,80 +3,73 @@
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:ctl="using:InteractionControls">
55

6-
<Style x:Key="DefaultZoomContentControlStyle" TargetType="ctl:ZoomContentControl">
7-
<Setter Property="Template">
8-
<Setter.Value>
9-
<ControlTemplate TargetType="ctl:ZoomContentControl">
10-
<Grid>
11-
<Grid.RowDefinitions>
12-
<RowDefinition Height="*" />
13-
<RowDefinition Height="Auto" />
14-
</Grid.RowDefinitions>
15-
<Grid.ColumnDefinitions>
16-
<ColumnDefinition Width="*" />
17-
<ColumnDefinition Width="Auto" />
18-
</Grid.ColumnDefinitions>
19-
<Border
6+
<Style x:Key="DefaultZoomContentControlStyle" TargetType="ctl:ZoomContentControl">
7+
<Setter Property="Template">
8+
<Setter.Value>
9+
<ControlTemplate TargetType="ctl:ZoomContentControl">
10+
<Grid>
11+
<Grid.RowDefinitions>
12+
<RowDefinition Height="*" />
13+
<RowDefinition Height="Auto" />
14+
</Grid.RowDefinitions>
15+
<Grid.ColumnDefinitions>
16+
<ColumnDefinition Width="*" />
17+
<ColumnDefinition Width="Auto" />
18+
</Grid.ColumnDefinitions>
19+
<Border
2020
Grid.Row="0"
2121
Grid.Column="0"
2222
Background="{TemplateBinding Background}">
23-
<ContentPresenter
23+
<ContentPresenter
2424
x:Name="PART_Presenter"
2525
Margin="{TemplateBinding Padding}"
2626
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
2727
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
2828
Content="{TemplateBinding Content}"
2929
ContentTemplate="{TemplateBinding ContentTemplate}">
30-
<ContentPresenter.RenderTransform>
31-
<TransformGroup>
32-
<ScaleTransform CenterX="{TemplateBinding HorizontalZoomCenter}" CenterY="{TemplateBinding VerticalZoomCenter}" ScaleX="{TemplateBinding ZoomLevel}" ScaleY="{TemplateBinding ZoomLevel}" />
33-
<TranslateTransform X="{TemplateBinding HorizontalOffset}" Y="{TemplateBinding VerticalOffset}" />
34-
</TransformGroup>
35-
</ContentPresenter.RenderTransform>
36-
</ContentPresenter>
37-
</Border>
38-
<!-- Vertical ScrollBar -->
39-
<ScrollBar
30+
<ContentPresenter.RenderTransform>
31+
<TransformGroup>
32+
<ScaleTransform CenterX="{TemplateBinding HorizontalZoomCenter}" CenterY="{TemplateBinding VerticalZoomCenter}" ScaleX="{TemplateBinding ZoomLevel}" ScaleY="{TemplateBinding ZoomLevel}" />
33+
<TranslateTransform X="{TemplateBinding HorizontalOffset}" Y="{TemplateBinding VerticalOffset}" />
34+
</TransformGroup>
35+
</ContentPresenter.RenderTransform>
36+
</ContentPresenter>
37+
</Border>
38+
<!-- Vertical ScrollBar -->
39+
<ScrollBar
4040
x:Name="PART_scrollV"
4141
Grid.Row="0"
4242
Grid.Column="1"
4343
HorizontalAlignment="Right"
4444
VerticalAlignment="Stretch"
45-
LargeChange="100"
45+
IndicatorMode="MouseIndicator"
46+
LargeChange="10"
4647
Maximum="{TemplateBinding VerticalMaxScroll}"
4748
Minimum="{TemplateBinding VerticalMinScroll}"
4849
Orientation="Vertical"
49-
SmallChange="10"
50-
ViewportSize="{TemplateBinding ViewPortHeight}"
51-
Value="{TemplateBinding VerticalOffset}" />
52-
<!-- Horizontal ScrollBar -->
53-
<TextBlock
54-
HorizontalAlignment="Stretch"
55-
VerticalAlignment="Center"
56-
FontSize="16"
57-
Foreground="Red"
58-
Text="{Binding Value, ElementName=PART_scrollH}" />
59-
<ScrollBar
50+
SmallChange="1"
51+
ViewportSize="{TemplateBinding ViewPortHeight}" />
52+
<!-- Horizontal ScrollBar -->
53+
<ScrollBar
6054
x:Name="PART_scrollH"
6155
Grid.Row="1"
6256
Grid.Column="0"
6357
HorizontalAlignment="Stretch"
6458
VerticalAlignment="Bottom"
6559
IndicatorMode="MouseIndicator"
66-
LargeChange="100"
60+
LargeChange="10"
6761
Maximum="{TemplateBinding HorizontalMaxScroll}"
6862
Minimum="{TemplateBinding HorizontalMinScroll}"
6963
Orientation="Horizontal"
70-
SmallChange="10"
71-
ViewportSize="{TemplateBinding ViewPortWidth}"
72-
Value="{TemplateBinding HorizontalOffset}" />
73-
</Grid>
74-
</ControlTemplate>
75-
</Setter.Value>
76-
</Setter>
77-
</Style>
64+
SmallChange="1"
65+
ViewportSize="{TemplateBinding ViewPortWidth}" />
66+
</Grid>
67+
</ControlTemplate>
68+
</Setter.Value>
69+
</Setter>
70+
</Style>
7871

79-
<Style TargetType="ctl:ZoomContentControl" BasedOn="{StaticResource DefaultZoomContentControlStyle}" />
72+
<Style BasedOn="{StaticResource DefaultZoomContentControlStyle}" TargetType="ctl:ZoomContentControl" />
8073

8174

8275
</ResourceDictionary>

UI/PhotoViewer/PhotoViewer/MainPage.xaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@
4040
IsActive="{Binding IsOn, ElementName=swEnable}">
4141
<StackPanel>
4242
<Image Source="https://uno-website-assets.s3.amazonaws.com/wp-content/uploads/2023/05/12134055/SeingBelieving_2apps-1-1-1024x358.png" />
43-
<TextBlock
44-
HorizontalAlignment="Center"
45-
AutomationProperties.AutomationId="HelloTextBlock"
46-
Text="Hello Uno Platform" />
4743
</StackPanel>
4844
</controls:ZoomContentControl>
4945
</Grid>

0 commit comments

Comments
 (0)