Skip to content

Commit

Permalink
Merge pull request #11 from Baka632/230803-AddAccessibilitySupport
Browse files Browse the repository at this point in the history
添加辅助功能支持
  • Loading branch information
Baka632 authored Aug 6, 2023
2 parents 3615b18 + 38d6cb6 commit dc827b5
Show file tree
Hide file tree
Showing 21 changed files with 489 additions and 472 deletions.
9 changes: 8 additions & 1 deletion src/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
x:Class="ArknightsStoryText.UWP.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:contract5NotPresent="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractNotPresent(Windows.Foundation.UniversalApiContract,5)"
xmlns:local="using:ArknightsStoryText.UWP">
<Application.Resources />
<Application.Resources>
<contract5NotPresent:Style BasedOn="{x:Null}" TargetType="AppBarButton" />
<contract5NotPresent:Style BasedOn="{x:Null}" TargetType="AppBarToggleButton" />
<contract5NotPresent:Style BasedOn="{x:Null}" TargetType="CommandBar">
<Setter Property="Background" Value="Transparent" />
</contract5NotPresent:Style>
</Application.Resources>
</Application>
18 changes: 8 additions & 10 deletions src/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ namespace ArknightsStoryText.UWP
sealed partial class App : Application
{
/// <summary>
/// 初始化单一实例应用程序对象。这是执行的创作代码的第一行,
/// 已执行,逻辑上等同于 main() 或 WinMain()。
/// 初始化单一实例应用程序对象。这是执行的创作代码的第一行,已执行,逻辑上等同于 main() 或 WinMain()。
/// </summary>
public App()
{
Expand All @@ -43,8 +42,7 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
#endif


// 不要在窗口已包含内容时重复应用程序初始化,
// 只需确保窗口处于活动状态
// 不要在窗口已包含内容时重复应用程序初始化,只需确保窗口处于活动状态
if (Window.Current.Content is not Frame rootFrame)
{
// 创建要充当导航上下文的框架,并导航到第一页
Expand All @@ -65,20 +63,20 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
{
if (rootFrame.Content == null)
{
// 当导航堆栈尚未还原时,导航到第一页,
// 并通过将所需信息作为导航参数传入来配置
// 参数
// 当导航堆栈尚未还原时,导航到第一页,并通过将所需信息作为导航参数传入来配置参数
rootFrame.Navigate(typeof(MainPage), e.Arguments);
}
// 确保当前窗口处于活动状态
Window.Current.Activate();
}

bool isMobile = AnalyticsInfo.VersionInfo.DeviceFamily == "Windows.Mobile";
if (isMobile is not true)

XamlControlsResources muxcStyle = new()
{
Resources.MergedDictionaries.Add(new XamlControlsResources());
}
ControlsResourcesVersion = isMobile ? ControlsResourcesVersion.Version1 : ControlsResourcesVersion.Version2
};
Resources.MergedDictionaries.Add(muxcStyle);

#region TitleBarColor
ApplicationViewTitleBar PresentationTitleBar = ApplicationView.GetForCurrentView().TitleBar;
Expand Down
13 changes: 6 additions & 7 deletions src/ArknightsStoryText.UWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<DefaultLanguage>zh-CN</DefaultLanguage>
<LangVersion>latest</LangVersion>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.19041.0</TargetPlatformVersion>
<TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.22000.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.16299.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
<FileAlignment>512</FileAlignment>
Expand Down Expand Up @@ -131,6 +131,9 @@
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="Commands\DelegateCommand.cs" />
<Compile Include="Controls\StoryTextExpander.xaml.cs">
<DependentUpon>StoryTextExpander.xaml</DependentUpon>
</Compile>
<Compile Include="Helpers\Converter\ObjectToFontFamilyOrFontSizeConverter.cs" />
<Compile Include="Helpers\FontHelper.cs" />
<Compile Include="Helpers\LocalizationHelper.cs" />
Expand Down Expand Up @@ -169,10 +172,6 @@
<Compile Include="Models\FontInfo.cs" />
<Compile Include="Models\StoryFileInfo.cs" />
<Compile Include="Models\StoryInfo.cs" />
<Compile Include="ViewModels\TextReadViewModel.Mobile.cs" />
<Compile Include="Views\TextReadPage.Mobile.xaml.cs">
<DependentUpon>TextReadPage.Mobile.xaml</DependentUpon>
</Compile>
<Compile Include="ViewModels\NotificationObject.cs" />
<Compile Include="ViewModels\TextMergeViewModel.cs" />
<Compile Include="ViewModels\TextReadViewModel.cs" />
Expand Down Expand Up @@ -257,7 +256,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Page Include="Views\TextReadPage.Mobile.xaml">
<Page Include="Controls\StoryTextExpander.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
Expand All @@ -284,7 +283,7 @@
<Version>6.2.14</Version>
</PackageReference>
<PackageReference Include="Microsoft.UI.Xaml">
<Version>2.6.3</Version>
<Version>2.7.3</Version>
</PackageReference>
<PackageReference Include="SharpDX.Direct2D1">
<Version>4.2.0</Version>
Expand Down
118 changes: 118 additions & 0 deletions src/Controls/StoryTextExpander.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<UserControl
x:Class="ArknightsStoryText.UWP.Controls.StoryTextExpander"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converter="using:ArknightsStoryText.UWP.Helpers.Converter"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:helper="using:ArknightsStoryText.UWP.Helpers"
xmlns:local="using:ArknightsStoryText.UWP.Controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:models="using:ArknightsStoryText.UWP.Models"
d:DataContext="{d:DesignInstance Type=local:StoryTextExpander}"
d:DesignHeight="300"
d:DesignWidth="400"
mc:Ignorable="d">

<StackPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<Grid
Grid.Column="0"
HorizontalAlignment="Stretch"
Background="Transparent"
Tapped="OnTitleGridTapped">
<TextBlock
HorizontalAlignment="Left"
AutomationProperties.AccessibilityView="Raw"
Style="{StaticResource TitleTextBlockStyle}"
Text="{x:Bind Title, Mode=OneWay}" />
</Grid>

<ToggleButton
Grid.Column="1"
Width="40"
Height="40"
HorizontalAlignment="Right"
AutomationProperties.Name="{x:Bind StoryTextViewableToggleButtonAutomationName, Mode=OneWay}"
Background="Transparent"
BorderThickness="0"
Click="OnStoryTextViewableToggleButtonClicked"
IsChecked="{x:Bind helper:XamlHelper.ReverseBoolean(IsExpanded), Mode=OneWay}"
IsTabStop="False"
ToolTipService.ToolTip="{x:Bind StoryTextViewableToggleButtonAutomationName, Mode=OneWay}">
<FontIcon
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontFamily="{ThemeResource SymbolThemeFontFamily}"
Glyph="{x:Bind ChevronIcon, Mode=OneWay}" />
</ToggleButton>
</Grid>
<StackPanel
Height="2"
Margin="0,5,0,5"
HorizontalAlignment="Stretch"
Background="{StaticResource AppBarSeparatorForegroundThemeBrush}" />
<Grid Grid.Column="0" HorizontalAlignment="Stretch">
<TextBlock
x:Name="StoryTextBlock"
Grid.Column="0"
HorizontalAlignment="Stretch"
FontFamily="{x:Bind FontFamily, Mode=OneWay}"
FontSize="{x:Bind FontSize, Mode=OneWay}"
IsTextSelectionEnabled="True"
Style="{StaticResource BodyTextBlockStyle}"
Text="{x:Bind Text, Mode=OneWay}"
TextWrapping="Wrap"
Visibility="{x:Bind StoryTextVisibility, Mode=OneWay}">
<TextBlock.RenderTransform>
<CompositeTransform />
</TextBlock.RenderTransform>
<TextBlock.Resources>
<Storyboard x:Name="StoryTextBlockShow">
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="StoryTextBlock" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0" Value="Visible" />
</ObjectAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="StoryTextBlock" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)">
<DiscreteDoubleKeyFrame KeyTime="0" Value="-10" />
<SplineDoubleKeyFrame
KeySpline="0.0, 0.0, 0.0, 1.0"
KeyTime="0:0:0.333"
Value="0" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="StoryTextBlock" Storyboard.TargetProperty="Opacity">
<DiscreteDoubleKeyFrame KeyTime="0" Value="0" />
<SplineDoubleKeyFrame
KeySpline="0.0, 0.0, 0.0, 1.0"
KeyTime="0:0:0.333"
Value="1" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>

<Storyboard x:Name="StoryTextBlockHide">
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="StoryTextBlock" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0:0:0.1" Value="Collapsed" />
</ObjectAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="StoryTextBlock" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)">
<DiscreteDoubleKeyFrame KeyTime="0" Value="0" />
<SplineDoubleKeyFrame
KeySpline="0.0, 0.0, 0.0, 1.0"
KeyTime="0:0:0.1"
Value="-10" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="StoryTextBlock" Storyboard.TargetProperty="Opacity">
<DiscreteDoubleKeyFrame KeyTime="0" Value="1" />
<SplineDoubleKeyFrame
KeySpline="0.0, 0.0, 0.0, 1.0"
KeyTime="0:0:0.1"
Value="0" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</TextBlock.Resources>
</TextBlock>
</Grid>
</StackPanel>
</UserControl>
138 changes: 138 additions & 0 deletions src/Controls/StoryTextExpander.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using ArknightsStoryText.UWP.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;

//https://go.microsoft.com/fwlink/?LinkId=234236 上介绍了“用户控件”项模板

namespace ArknightsStoryText.UWP.Controls
{
public sealed partial class StoryTextExpander : UserControl
{
public StoryTextExpander()
{
this.InitializeComponent();
}

/// <summary>
/// 获取或设置剧情文本的标题
/// </summary>
public string Title
{
get => (string)GetValue(TitleProperty);
set => SetValue(TitleProperty, value);
}

/// <summary>
/// 用以标识 <see cref="StoryTextTitle"/> 的依赖属性
/// </summary>
public static readonly DependencyProperty TitleProperty =
DependencyProperty.Register("Title", typeof(string), typeof(StoryTextExpander), new PropertyMetadata(null));

/// <summary>
/// 获取或设置剧情文本
/// </summary>
public string Text
{
get => (string)GetValue(TextProperty);
set => SetValue(TextProperty, value);
}

/// <summary>
/// 用以标识 <see cref="StoryText"/> 的依赖属性
/// </summary>
public static readonly DependencyProperty TextProperty =
DependencyProperty.Register("Text", typeof(string), typeof(StoryTextExpander), new PropertyMetadata(null));

/// <summary>
/// 获取或设置控件是否展开的值
/// </summary>
public bool IsExpanded
{
get => (bool)GetValue(IsExpandedProperty);
set
{
SetValue(IsExpandedProperty, value);
OnIsExpandedChanged(value);
}
}

private void OnIsExpandedChanged(bool value)
{
if (value)
{
//状态:展开
StoryTextBlockShow.Begin();
//StoryTextVisibility = Visibility.Visible;
ChevronIcon = "\uE70E";
StoryTextViewableToggleButtonAutomationName = "ClickToCollapse".GetLocalized();
}
else
{
//状态:折叠
StoryTextBlockHide.Begin();
//StoryTextVisibility = Visibility.Collapsed;
ChevronIcon = "\uE70D";
StoryTextViewableToggleButtonAutomationName = "ClickToExpand".GetLocalized();
}
}

/// <summary>
/// 用以标识 <see cref="IsExpanded"/> 的依赖属性
/// </summary>
public static readonly DependencyProperty IsExpandedProperty =
DependencyProperty.Register("IsExpanded", typeof(bool), typeof(StoryTextExpander), new PropertyMetadata(true));

#region Private Dependency Property
private string ChevronIcon
{
get => (string)GetValue(ChevronIconProperty);
set => SetValue(ChevronIconProperty, value);
}

private static readonly DependencyProperty ChevronIconProperty =
DependencyProperty.Register("ChevronIcon", typeof(string), typeof(StoryTextExpander), new PropertyMetadata("\uE70E"));

private Visibility StoryTextVisibility
{
get => (Visibility)GetValue(StoryTextVisibilityProperty);
set => SetValue(StoryTextVisibilityProperty, value);
}

private static readonly DependencyProperty StoryTextVisibilityProperty =
DependencyProperty.Register("StoryTextVisibility", typeof(Visibility), typeof(StoryTextExpander), new PropertyMetadata(Visibility.Visible));

private string StoryTextViewableToggleButtonAutomationName
{
get => (string)GetValue(StoryTextViewableToggleButtonAutomationNameProperty);
set => SetValue(StoryTextViewableToggleButtonAutomationNameProperty, value);
}

// Using a DependencyProperty as the backing store for StoryTextViewableToggleButtonAutomationName. This enables animation, styling, binding, etc...
private static readonly DependencyProperty StoryTextViewableToggleButtonAutomationNameProperty =
DependencyProperty.Register("StoryTextViewableToggleButtonAutomationName", typeof(string), typeof(StoryTextExpander), new PropertyMetadata("ClickToCollapse".GetLocalized()));
#endregion

private void OnTitleGridTapped(object sender, TappedRoutedEventArgs e)
{
IsExpanded = !IsExpanded;
}

private void OnStoryTextViewableToggleButtonClicked(object sender, RoutedEventArgs e)
{
ToggleButton toggleButton = (ToggleButton)sender;
IsExpanded = !toggleButton.IsChecked.Value;
}
}
}
20 changes: 20 additions & 0 deletions src/Helpers/XamlHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,24 @@ public static Visibility ReverseVisibility(bool value)
false => Visibility.Visible,
};
}

public static Visibility ToVisibility(bool? value)
{
return value switch
{
true => Visibility.Collapsed,
false => Visibility.Visible,
null => Visibility.Collapsed
};
}

public static Visibility ToVisibility(bool? value, Visibility defaultVisibilityForNull = Visibility.Collapsed)
{
return value switch
{
true => Visibility.Collapsed,
false => Visibility.Visible,
null => defaultVisibilityForNull
};
}
}
Loading

0 comments on commit dc827b5

Please sign in to comment.