-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathVisibilityToBoolConverter.cs
More file actions
37 lines (34 loc) · 1.79 KB
/
VisibilityToBoolConverter.cs
File metadata and controls
37 lines (34 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace CommunityToolkit.WinUI.Converters;
/// <summary>
/// This class converts a Visibility enumeration to a boolean value.
/// </summary>
public partial class VisibilityToBoolConverter : IValueConverter
{
/// <summary>
/// Convert a <see cref="Visibility"/> value to boolean.
/// </summary>
/// <param name="value">The <see cref="Visibility"/> value to convert.</param>
/// <param name="targetType">The type of the target property, as a type reference.</param>
/// <param name="parameter">Optional parameter. Not used.</param>
/// <param name="language">The language of the conversion. Not used</param>
/// <returns>The value to be passed to the target dependency property.</returns>
public object Convert(object value, Type targetType, object parameter, string language)
{
return value is Visibility visibility && visibility == Visibility.Visible;
}
/// <summary>
/// Convert back a boolean value to <see cref="Visibility"/>.
/// </summary>
/// <param name="value">The <see cref="Visibility"/> value to convert back.</param>
/// <param name="targetType">The type of the target property, as a type reference.</param>
/// <param name="parameter">Optional parameter. Not used.</param>
/// <param name="language">The language of the conversion. Not used</param>
/// <returns>The value to be passed to the target dependency property.</returns>
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
return (value is bool bl && bl) ? Visibility.Visible : Visibility.Collapsed;
}
}