-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
60 additions
and
5 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
...loader/UnoFileDownloader/UnoFileDownloader/Presentation/Converters/VisibilityConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} 的转换。"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters