Skip to content

Commit

Permalink
优化下载任务按钮
Browse files Browse the repository at this point in the history
  • Loading branch information
lindexi committed Dec 20, 2023
1 parent 3945f72 commit 0af89fb
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Microsoft.UI.Xaml.Data;

namespace UnoFileDownloader.Presentation.Converters
{
public class VisibilityConverter : IValueConverter
{
public Visibility DefaultVisibility { set; get; }

public bool? Visible { set; get; }

/// <summary>
/// 获取或设置 <see cref="Visibility.Collapsed"/> 所对应的值。
/// </summary>
public bool? Collapsed { get; set; }

public object Convert(object value, Type targetType, object parameter, string language)
{
if (Equals(value, Visible))
{
return Visibility.Visible;
}
if (Equals(value, Collapsed))
{
return Visibility.Collapsed;
}
return DefaultVisibility;
}

public object? ConvertBack(object value, Type targetType, object parameter, string language)
{
if (value == null)
{
throw new ArgumentNullException();
}
Visibility visibility = (Visibility) value;
switch (visibility)
{
case Visibility.Visible:
return Visible;
case Visibility.Collapsed:
return Collapsed;
default:
throw new ArgumentException($"不支持指定值 {value} 的转换。");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:models="using:UnoFileDownloader.Business.Models"
xmlns:converters="using:UnoFileDownloader.Presentation.Converters"
mc:Ignorable="d"
Background="{ThemeResource BackgroundBrush}" d:DataContext="{d:DesignInstance local:BindableMainModel}">

Expand All @@ -19,6 +20,7 @@
<Setter Property="VerticalAlignment" Value="Stretch"></Setter>
<Setter Property="HorizontalAlignment" Value="Stretch"></Setter>
</Style>
<converters:VisibilityConverter x:Key="CollapsedWhenFalse" Visible="True" Collapsed="False"/>
</Page.Resources>
<Grid>
<Grid.RowDefinitions>
Expand Down Expand Up @@ -126,7 +128,7 @@
<Setter Property="Padding" Value="1,0" />
<Setter Property="Margin" Value="-1,0,-1,-1" />
<Setter Property="BorderBrush" Value="Gray" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="BorderThickness" Value="0 0 0 1" />
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
Expand All @@ -146,8 +148,8 @@
<ColumnDefinition Width="100" />
<ColumnDefinition Width="100" />
<ColumnDefinition Width="200" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="50" />
<ColumnDefinition Width="50" />
</Grid.ColumnDefinitions>
<TextBlock
Grid.Column="0"
Expand All @@ -170,7 +172,7 @@
Grid.Column="5"
Style="{StaticResource TitleBarButtonStyle}"
AutomationProperties.Name="[Open Download Item File]"
>
Visibility="{Binding IsFinished,Converter={StaticResource CollapsedWhenFalse},Mode=OneWay}">
<Button.Content>
<SymbolIcon Symbol="OpenFile" />
</Button.Content>
Expand All @@ -180,7 +182,7 @@
Grid.Column="6"
Style="{StaticResource TitleBarButtonStyle}"
AutomationProperties.Name="[Open Contain Folder]"
>
Visibility="{Binding IsFinished,Converter={StaticResource CollapsedWhenFalse},Mode=OneWay}">
<Button.Content>
<SymbolIcon Symbol="Folder" />
</Button.Content>
Expand Down

0 comments on commit 0af89fb

Please sign in to comment.