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

Enable scrolling behavior to work correctly by making sure there is background of transparent on the panels for containers. #214

Merged
merged 6 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions src/Consolonia.Core/Infrastructure/ConsoloniaApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public override void OnFrameworkInitializationCompleted()
DataTemplates.Add(new FuncDataTemplate<object>(
(data, _) =>
{
if (data != null && data is string)
if (data != null)
{
var result = new ConsoloniaAccessText();
// ReSharper disable AccessToStaticMemberViaDerivedType
result.Bind(TextBlock.TextProperty,
result.GetObservable(Control.DataContextProperty));
result.GetBindingObservable(Control.DataContextProperty, x => x?.ToString()));
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,52 +12,44 @@
<CheckBox IsChecked="{Binding AllowAutoHide}"
Content="Allow auto hide" />

<StackPanel Orientation="Vertical"
<StackPanel Orientation="Horizontal"
Spacing="1">
<TextBlock Text="Horizontal Scroll" />
<ComboBox ItemsSource="{Binding AvailableVisibility}"
<Label Content="Horizontal Scroll"
Target="HorizontalScrollOptions" />
<ComboBox Name="HorizontalScrollOptions"
ItemsSource="{Binding AvailableVisibility}"
Width="20"
SelectedItem="{Binding HorizontalScrollVisibility}" />
</StackPanel>

<StackPanel Orientation="Vertical"
<StackPanel Orientation="Horizontal"
Spacing="1">
<TextBlock Text="Vertical Scroll" />
<ComboBox ItemsSource="{Binding AvailableVisibility}"
<Label Content="Vertical Scroll"
Target="VerticalScrollOptions" />
<ComboBox Name="VerticalScrollOptions"
ItemsSource="{Binding AvailableVisibility}"
Width="20"
SelectedItem="{Binding VerticalScrollVisibility}" />
</StackPanel>
</StackPanel>

<ScrollViewer x:Name="ScrollViewer"
Grid.Row="1"
Width="30"
Height="20"
AllowAutoHide="{Binding AllowAutoHide}"
HorizontalScrollBarVisibility="{Binding HorizontalScrollVisibility}"
VerticalScrollBarVisibility="{Binding VerticalScrollVisibility}"
Focusable="True">
<TextBlock xml:space="preserve"
Foreground="{DynamicResource ThemeForegroundBrush}">Focus to ScrollViewer
/; ;\
__ \\____//
/{_\_/ `'\____
\___ (o) (o }
_____________________________/ :--'
,-,'`@@@@@@@@ @@@@@@ \_ `__\
;:( @@@@@@@@@ @@@ \___(o'o)
:: ) @@@@ @@@@@@ ,'@@( `===='
:: : @@@@@: @@@@ `@@@:
:: \ @@@@@: @@@@@@@) ( '@@@'
;; /\ /`, @@@@@@@@@\ :@@@@@)
::/ ) {_----------------: :~`,~~;
;;'`; : ) : / `; ;
;;;; : : ; : ; ; :
`'`' / : : : : : :
)_ \__; ";" :_ ; \_\ `,','
:__\ \ * `,'* \ \ : \ * 8`;'* *
`^' \ :/ `^' `-^-' \v/ : \/
Bill Ames
</TextBlock>

<ItemsControl ItemsSource="{Binding Cows}"
Width="200">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Foreground="{DynamicResource ThemeForegroundBrush}"
Text="{Binding}"
Padding="0"
Margin="0" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</Grid>
</UserControl>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
Expand All @@ -24,6 +25,8 @@ public GalleryScrollViewer()
public class ScrollViewerPageViewModel : ViewModelBase
{
private readonly bool _allowAutoHide;

private readonly string[] _cows = Array.Empty<string>();
private readonly ScrollBarVisibility _horizontalScrollVisibility;
private readonly ScrollBarVisibility _verticalScrollVisibility;

Expand All @@ -38,8 +41,33 @@ public ScrollViewerPageViewModel()
};

HorizontalScrollVisibility = ScrollBarVisibility.Auto;
VerticalScrollVisibility = ScrollBarVisibility.Auto;
VerticalScrollVisibility = ScrollBarVisibility.Visible;
AllowAutoHide = true;
var text = new List<string>();
for (int i = 0; i < 30; i++)
text.AddRange("""
/; ;\
__ \\____//
/{_\_/ `'\____
\___ (o) (o }
_____________________________/ :--'
,-,'`@@@@@@@@ @@@@@@ \_ `__\
;:( @@@@@@@@@ @@@ \___(o'o)
:: ) @@@@ @@@@@@ ,'@@( `===='
:: : @@@@@: @@@@ `@@@:
:: \ @@@@@: @@@@@@@) ( '@@@'
;; /\ /`, @@@@@@@@@\ :@@@@@)
::/ ) {_----------------: :~`,~~;
;;'`; : ) : / `; ;
;;;; : : ; : ; ; :
`'`' / : : : : : :
)_ \__; ";" :_ ; \_\ `,','
:__\ \ * `,'* \ \ : \ * 8`;'* *
`^' \ :/ `^' `-^-' \v/ : \/
Bill Ames

""".Split(['\r', '\n'], StringSplitOptions.RemoveEmptyEntries));
Cows = [.. text];
}

public bool AllowAutoHide
Expand All @@ -61,6 +89,12 @@ public ScrollBarVisibility VerticalScrollVisibility
}

public List<ScrollBarVisibility> AvailableVisibility { get; }

public string[] Cows
{
get => _cows;
init => RaiseAndSetIfChanged(ref _cows, value);
}
}

public class ViewModelBase : INotifyPropertyChanged
Expand Down
3 changes: 2 additions & 1 deletion src/Consolonia.Themes/Templates/Controls/ComboBoxItem.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
Value="Left" />
<Setter Property="Template">
<ControlTemplate>
<helpers:CaretControl IsCaretShown="{TemplateBinding IsFocused}">
<helpers:CaretControl IsCaretShown="{TemplateBinding IsFocused}"
Background="Transparent">
<ContentPresenter Name="PART_ContentPresenter"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
Expand Down
3 changes: 2 additions & 1 deletion src/Consolonia.Themes/Templates/Controls/DataGrid.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
<Setter Property="Template">
<ControlTemplate>
<Grid ColumnDefinitions="*,Auto"
Background="{TemplateBinding Background}">
Background="Transparent">
<ContentPresenter ContentTemplate="{TemplateBinding ContentTemplate}"
Content="{TemplateBinding Content}"
Margin="{TemplateBinding Padding}"
Background="{TemplateBinding Background}"
TextBlock.Foreground="{TemplateBinding Foreground}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
Expand Down
25 changes: 12 additions & 13 deletions src/Consolonia.Themes/Templates/Controls/ListBoxItem.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,18 @@
Value="{DynamicResource ThemeTransparentBrush}" />
<Setter Property="Template">
<ControlTemplate>
<Panel Background="{TemplateBinding Background}">
<helpers:CaretControl Foreground="{TemplateBinding Foreground}"
IsCaretShown="{TemplateBinding IsFocused}">
<ContentPresenter Name="PART_ContentPresenter"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Content="{TemplateBinding Content}"
Padding="{TemplateBinding Padding}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" />
</helpers:CaretControl>
</Panel>
<helpers:CaretControl Foreground="{TemplateBinding Foreground}"
IsCaretShown="{TemplateBinding IsFocused}">
<ContentPresenter Name="PART_ContentPresenter"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Content="{TemplateBinding Content}"
Padding="{TemplateBinding Padding}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" />
</helpers:CaretControl>
</ControlTemplate>
</Setter>

Expand Down
32 changes: 17 additions & 15 deletions src/Consolonia.Themes/Templates/Controls/ScrollViewer.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,23 @@
<Grid x:Name="PART_Root"
RowDefinitions="*,Auto"
ColumnDefinitions="*,Auto">
<ScrollContentPresenter Name="PART_ContentPresenter"
Padding="{TemplateBinding Padding}"
HorizontalSnapPointsType="{TemplateBinding HorizontalSnapPointsType}"
VerticalSnapPointsType="{TemplateBinding VerticalSnapPointsType}"
HorizontalSnapPointsAlignment="{TemplateBinding HorizontalSnapPointsAlignment}"
VerticalSnapPointsAlignment="{TemplateBinding VerticalSnapPointsAlignment}"
Background="{TemplateBinding Background}"
ScrollViewer.IsScrollInertiaEnabled="True">
<ScrollContentPresenter.GestureRecognizers>
<ScrollGestureRecognizer
CanHorizontallyScroll="{Binding CanHorizontallyScroll, ElementName=PART_ContentPresenter}"
CanVerticallyScroll="{Binding CanVerticallyScroll, ElementName=PART_ContentPresenter}"
IsScrollInertiaEnabled="{Binding (ScrollViewer.IsScrollInertiaEnabled), ElementName=PART_ContentPresenter}" />
</ScrollContentPresenter.GestureRecognizers>
</ScrollContentPresenter>
<Panel Background="{TemplateBinding Background}">
<ScrollContentPresenter Name="PART_ContentPresenter"
Padding="{TemplateBinding Padding}"
HorizontalSnapPointsType="{TemplateBinding HorizontalSnapPointsType}"
VerticalSnapPointsType="{TemplateBinding VerticalSnapPointsType}"
HorizontalSnapPointsAlignment="{TemplateBinding HorizontalSnapPointsAlignment}"
VerticalSnapPointsAlignment="{TemplateBinding VerticalSnapPointsAlignment}"
Background="Transparent"
ScrollViewer.IsScrollInertiaEnabled="True">
<ScrollContentPresenter.GestureRecognizers>
<ScrollGestureRecognizer
CanHorizontallyScroll="{Binding CanHorizontallyScroll, ElementName=PART_ContentPresenter}"
CanVerticallyScroll="{Binding CanVerticallyScroll, ElementName=PART_ContentPresenter}"
IsScrollInertiaEnabled="{Binding (ScrollViewer.IsScrollInertiaEnabled), ElementName=PART_ContentPresenter}" />
</ScrollContentPresenter.GestureRecognizers>
</ScrollContentPresenter>
</Panel>
<ScrollBar Name="PART_HorizontalScrollBar"
Orientation="Horizontal"
Grid.Row="1"
Expand Down
Loading