Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.

namespace Wpf.Ui.Gallery.ViewModels.Pages.Collections;

public sealed partial class ListViewScrollViewModel : ViewModel
{
[ObservableProperty]
private ObservableCollection<string> _bigArray = GenerateBigArray();

private static ObservableCollection<string> GenerateBigArray()
{
var result = new ObservableCollection<string>();
for (int i = 0; i < 500; i++)
{
result.Add($"Item {i + 1}");
}

return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ public int ListViewSelectionModeComboBoxSelectedIndex
[ObservableProperty]
private ObservableCollection<Person> _basicListViewItems = GeneratePersons();

[ObservableProperty]
private ObservableCollection<string> _bigArray = GenerateBigArray();

private static ObservableCollection<string> GenerateBigArray()
{
var result = new ObservableCollection<string>();
for (int i = 0; i < 500; i++)
{
result.Add($"Item {i + 1}");
}
return result;
}

private static ObservableCollection<Person> GeneratePersons()
{
var random = new Random();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public partial class MainWindowViewModel(IStringLocalizer<Translations> localize
new NavigationViewItem(nameof(System.Windows.Controls.DataGrid), typeof(DataGridPage)),
new NavigationViewItem(nameof(ListBox), typeof(ListBoxPage)),
new NavigationViewItem(nameof(Ui.Controls.ListView), typeof(ListViewPage)),
new NavigationViewItem("ListViewNoPageScroll", typeof(ListViewScrollPage)),
new NavigationViewItem(nameof(TreeView), typeof(TreeViewPage)),
#if DEBUG
new NavigationViewItem("TreeList", typeof(TreeListPage)),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<Page x:Class="Wpf.Ui.Gallery.Views.Pages.Collections.ListViewScrollPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wpf.Ui.Gallery.Views.Pages.Collections"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
xmlns:system="clr-namespace:System;assembly=System.Runtime"
xmlns:controls="clr-namespace:Wpf.Ui.Gallery.Controls"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
Title="ListViewScrollPage"
d:DataContext="{d:DesignInstance local:ListViewPage,
IsDesignTimeCreatable=False}"
ui:Design.Background="{DynamicResource ApplicationBackgroundBrush}"
ui:Design.Foreground="{DynamicResource TextFillColorPrimaryBrush}"
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
ui:NavigationView.IsScrollable="False">

<ui:Card VerticalAlignment="Top" VerticalContentAlignment="Stretch" Padding="14" Margin="0,0,0,24">
<ui:ListView ItemsSource="{Binding ViewModel.BigArray, Mode=OneWay}"
d:ItemsSource="{d:SampleData ItemCount=10}"
BorderThickness="0" SelectionMode="Single"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Auto"
TextOptions.TextFormattingMode="Display"
TextOptions.TextRenderingMode="ClearType"
VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.VirtualizationMode="Recycling"
RenderOptions.ClearTypeHint="Enabled">
<ListView.ItemTemplate>
<DataTemplate DataType="{x:Type system:String}">
<ui:TextBlock FontSize="12" VerticalAlignment="Top"
Text="{Binding}"
FontFamily="Consolas, Cascadia Mono, Segoe UI Mono, Courier New"
Foreground="{DynamicResource TextFillColorSecondaryBrush}"/>
</DataTemplate>
</ListView.ItemTemplate>
</ui:ListView>
</ui:Card>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.

using System.Windows;
using System.Windows.Controls;
using Wpf.Ui.Controls;
using Wpf.Ui.Gallery.ControlsLookup;
using Wpf.Ui.Gallery.ViewModels.Pages.Collections;

namespace Wpf.Ui.Gallery.Views.Pages.Collections;
/// <summary>
/// Interaction logic for ListViewScrollPage.xaml
/// </summary>
[GalleryPage("Selectable list.", SymbolRegular.GroupList24)]
public partial class ListViewScrollPage : INavigableView<ListViewScrollViewModel>
{
/// <inheritdoc />
public ListViewScrollViewModel ViewModel { get; set; }

public ListViewScrollPage(ListViewScrollViewModel viewModel)
{
ViewModel = viewModel;
DataContext = this;

InitializeComponent();
}

}
4 changes: 2 additions & 2 deletions src/Wpf.Ui.Tray/Controls/NotifyIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,8 @@ private void RegisterHandlers()

private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
{
// Menu?.DataContext = e.NewValue;
if (Menu != null)
// Update ContextMenu DataContext when NotifyIcon DataContext changes
if (Menu != null && e.NewValue != null)
{
Menu.DataContext = e.NewValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,41 @@
public static void SetHeaderContent(FrameworkElement target, object? headerContent) =>
target.SetValue(HeaderContentProperty, headerContent);

// ============================================================
// IsScrollable Attached Property
// ============================================================

/// <summary>
/// Identifies the <see cref="IsScrollable"/> attached property.

Check warning on line 53 in src/Wpf.Ui/Controls/NavigationView/NavigationView.AttachedProperties.cs

View workflow job for this annotation

GitHub Actions / build

XML comment has cref attribute 'IsScrollable' that could not be resolved
/// </summary>
public static readonly DependencyProperty IsScrollableProperty = DependencyProperty.RegisterAttached(
"IsScrollable",
typeof(bool),
typeof(NavigationView),
new FrameworkPropertyMetadata(true)
);

/// <summary>
/// Gets the value of the <see cref="IsScrollableProperty"/> attached property for a specified element.
/// </summary>
/// <param name="element">The element from which to read the property value.</param>
/// <returns><see langword="true"/> if the content of the page hosted in <see cref="NavigationView"/> should be scrollable; otherwise, <see langword="false"/>.</returns>
[AttachedPropertyBrowsableForType(typeof(DependencyObject))]
public static bool GetIsScrollable(DependencyObject element)
{
return (bool)element.GetValue(IsScrollableProperty);
}

/// <summary>
/// Sets the value of the <see cref="IsScrollableProperty"/> attached property for a specified element.
/// </summary>
/// <param name="element">The element on which to set the property value.</param>
/// <param name="value">The value to set. <see langword="false"/> to disable scrolling on the <see cref="NavigationView"/> content presenter.</param>
public static void SetIsScrollable(DependencyObject element, bool value)
{
element.SetValue(IsScrollableProperty, value);
}

// ============================================================
// NavigationParent Attached Property
// ============================================================
Expand Down
24 changes: 24 additions & 0 deletions src/Wpf.Ui/Controls/NavigationView/NavigationView.Navigation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Windows.Controls;
using Wpf.Ui.Abstractions;

// ReSharper disable once CheckNamespace
Expand Down Expand Up @@ -355,7 +356,7 @@
{
if (PageToNavigationItemDictionary.TryGetValue(page, out INavigationViewItem? navItem))
{
navItem.Content = headerContent;

Check warning on line 359 in src/Wpf.Ui/Controls/NavigationView/NavigationView.Navigation.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference assignment.
UpdateBreadcrumbContents();
}
}
Expand All @@ -382,10 +383,33 @@

_ = frame.RemoveBackEntry();

// Update content ScrollViewer based on page's IsScrollable property
UpdateContentScrollViewer(e.Content);

/*var replaced = 1;
((NavigationViewContentPresenter)sender).JournalOwnership =*/
}

private void UpdateContentScrollViewer(object? content)
{
if (ContentScrollViewer is null)
{
return;
}

var isScrollable = true;

if (content is DependencyObject dependencyObject)
{
isScrollable = NavigationView.GetIsScrollable(dependencyObject);
}

ContentScrollViewer.SetCurrentValue(
ScrollViewer.VerticalScrollBarVisibilityProperty,
isScrollable ? ScrollBarVisibility.Auto : ScrollBarVisibility.Disabled
);
}

private void AddToNavigationStack(
INavigationViewItem viewItem,
bool addToNavigationStack,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
// Based on Windows UI Library
// Copyright(c) Microsoft Corporation.All rights reserved.

using System.Windows.Controls;

// ReSharper disable once CheckNamespace

namespace Wpf.Ui.Controls;

/// <content>
Expand All @@ -30,10 +33,11 @@ namespace Wpf.Ui.Controls;
Name = TemplateElementAutoSuggestBoxSymbolButton,
Type = typeof(System.Windows.Controls.Button)
)]
[TemplatePart(Name = TemplateElementContentScrollViewer, Type = typeof(ScrollViewer))]
public partial class NavigationView
{
/// <summary>
/// Template element represented by the <c>PART_MenuItemsItemsControl</c> name.
/// Template element represented by the <c>PART_NavigationViewContentPresenter</c> name.
/// </summary>
private const string TemplateElementNavigationViewContentPresenter =
"PART_NavigationViewContentPresenter";
Expand Down Expand Up @@ -63,6 +67,11 @@ public partial class NavigationView
/// </summary>
private const string TemplateElementAutoSuggestBoxSymbolButton = "PART_AutoSuggestBoxSymbolButton";

/// <summary>
/// Template element represented by the <c>PART_ContentScrollViewer</c> name.
/// </summary>
private const string TemplateElementContentScrollViewer = "PART_ContentScrollViewer";

/// <summary>
/// Gets or sets the control responsible for rendering the content.
/// </summary>
Expand Down Expand Up @@ -93,6 +102,11 @@ public partial class NavigationView
/// </summary>
protected System.Windows.Controls.Button? AutoSuggestBoxSymbolButton { get; set; }

/// <summary>
/// Gets or sets the <see cref="ScrollViewer"/> that hosts the content of the <see cref="Page"/>.
/// </summary>
protected ScrollViewer? ContentScrollViewer { get; set; }

/// <inheritdoc />
public override void OnApplyTemplate()
{
Expand Down Expand Up @@ -121,6 +135,11 @@ public override void OnApplyTemplate()
{
NavigationViewContentPresenter.Navigated -= OnNavigationViewContentPresenterNavigated;
NavigationViewContentPresenter.Navigated += OnNavigationViewContentPresenterNavigated;

// We need to wait for the NavigationViewContentPresenter to apply its template
// so we can find the ContentScrollViewer
NavigationViewContentPresenter.ApplyTemplate();
FindContentScrollViewer();
}

if (
Expand Down Expand Up @@ -151,6 +170,20 @@ is System.Windows.Controls.Button autoSuggestBoxSymbolButton
}
}

private void FindContentScrollViewer()
{
if (NavigationViewContentPresenter?.Template is null)
{
return;
}

// Try to find the ContentScrollViewer within the NavigationViewContentPresenter's template
if (NavigationViewContentPresenter.Template.FindName(TemplateElementContentScrollViewer, NavigationViewContentPresenter) is ScrollViewer scrollViewer)
{
ContentScrollViewer = scrollViewer;
}
}

protected T GetTemplateChild<T>(string name)
where T : DependencyObject
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!--
<!--
This Source Code Form is subject to the terms of the MIT License.
If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
Copyright (C) Leszek Pomianowski and WPF UI Contributors.
Expand All @@ -19,6 +19,7 @@

<ControlTemplate x:Key="DefaultNavigationViewContentPresenterWithDynamicScrollViewerControlTemplate" TargetType="{x:Type controls:NavigationViewContentPresenter}">
<controls:DynamicScrollViewer
x:Name="PART_ContentScrollViewer"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Focusable="False">
Expand Down
Loading