未验证 提交 7099d04a 编写于 作者: J Jérôme Laban 提交者: GitHub

Merge pull request #12359 from unoplatform/dev/mazi/singleselectionfocus

feat: Support for `SingleSelectionFollowsFocus`
......@@ -1970,6 +1970,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ListView\ListView_SingleSelection_Focus.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ListView\ListView_Resizing.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
......@@ -6426,6 +6430,9 @@
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ListView\ListView_Focus.xaml.cs">
<DependentUpon>ListView_Focus.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ListView\ListView_SingleSelection_Focus.xaml.cs">
<DependentUpon>ListView_SingleSelection_Focus.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ListView\ListView_Resizing.xaml.cs">
<DependentUpon>ListView_Resizing.xaml</DependentUpon>
</Compile>
......
<UserControl
x:Class="UITests.Shared.Windows_UI_Xaml_Controls.ListView.ListView_SingleSelection_Focus"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:UITests.Shared.Windows_UI_Xaml_Controls.ListView"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DesignHeight="300"
d:DesignWidth="400"
mc:Ignorable="d">
<StackPanel Spacing="8">
<TextBlock FontWeight="Bold" Text="SingleSelectionFollowsFocus = true" />
<ListView
x:Name="ListView1"
Width="100"
Height="200"
BorderBrush="Black"
BorderThickness="1"
SelectionMode="Single"
SingleSelectionFollowsFocus="True" />
<TextBlock Text="{x:Bind ListView1.SelectedItem, Mode=OneWay}" />
<TextBlock FontWeight="Bold" Text="SingleSelectionFollowsFocus = false" />
<ListView
x:Name="ListView2"
Width="100"
Height="200"
BorderBrush="Black"
BorderThickness="1"
SelectionMode="Single"
SingleSelectionFollowsFocus="False" />
<TextBlock Text="{x:Bind ListView2.SelectedItem, Mode=OneWay}" />
</StackPanel>
</UserControl>
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Uno.UI.Samples.Controls;
using Uno.UI.Samples.UITests.Helpers;
using Windows.Foundation;
using Windows.Foundation.Collections;
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;
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
namespace UITests.Shared.Windows_UI_Xaml_Controls.ListView
{
[Sample("ListView", IsManualTest = true, IgnoreInSnapshotTests = true)]
public sealed partial class ListView_SingleSelection_Focus : UserControl
{
public ListView_SingleSelection_Focus()
{
this.InitializeComponent();
ListView1.ItemsSource = Enumerable.Range(0, 30).Select(i => i.ToString()).ToArray();
ListView2.ItemsSource = Enumerable.Range(0, 30).Select(i => i.ToString()).ToArray();
}
}
}
......@@ -113,7 +113,7 @@ namespace Windows.UI.Xaml.Controls
}
}
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public bool SingleSelectionFollowsFocus
{
......@@ -252,7 +252,7 @@ namespace Windows.UI.Xaml.Controls
typeof(global::Windows.UI.Xaml.Controls.ListViewBase),
new Windows.UI.Xaml.FrameworkPropertyMetadata(default(bool)));
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public static global::Windows.UI.Xaml.DependencyProperty SingleSelectionFollowsFocusProperty { get; } =
Windows.UI.Xaml.DependencyProperty.Register(
......
using Windows.UI.Xaml;
namespace Windows.UI.Xaml.Controls;
public partial class ListViewBase
{
/// <summary>
/// Gets or sets a value that indicates whether item selection changes when keyboard focus changes.
/// </summary>
public bool SingleSelectionFollowsFocus
{
get => (bool)GetValue(SingleSelectionFollowsFocusProperty);
set => SetValue(SingleSelectionFollowsFocusProperty, value);
}
/// <summary>
/// Identifies the SingleSelectionFollowsFocus dependency property.
/// </summary>
public static DependencyProperty SingleSelectionFollowsFocusProperty { get; } =
DependencyProperty.Register(
nameof(SingleSelectionFollowsFocus),
typeof(bool),
typeof(ListViewBase),
new FrameworkPropertyMetadata(true));
}
......@@ -29,6 +29,7 @@ using Windows.Foundation;
using Uno.UI;
using Windows.UI.Xaml.Input;
using Windows.System;
using Uno.UI.Xaml.Input;
namespace Windows.UI.Xaml.Controls
{
......@@ -130,7 +131,8 @@ namespace Windows.UI.Xaml.Controls
}
// If selection mode is single, moving focus also selects the item
if (SelectionMode == ListViewSelectionMode.Single)
if (SelectionMode == ListViewSelectionMode.Single &&
SingleSelectionFollowsFocus)
{
SelectedIndex = index;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册