-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
5 changed files
with
95 additions
and
11 deletions.
There are no files selected for viewing
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,39 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.Windows; | ||
using System.Windows.Data; | ||
|
||
namespace pg.DarkSky.Wpf.Converters | ||
{ | ||
[ValueConversion(typeof(bool), typeof(Visibility))] | ||
public sealed class BoolToVisibilityConverter : IValueConverter | ||
{ | ||
public Visibility TrueValue { get; set; } | ||
public Visibility FalseValue { get; set; } | ||
|
||
public BoolToVisibilityConverter() | ||
{ | ||
// set defaults | ||
TrueValue = Visibility.Visible; | ||
FalseValue = Visibility.Collapsed; | ||
} | ||
|
||
public object Convert(object value, Type targetType, | ||
object parameter, CultureInfo culture) | ||
{ | ||
if (!(value is bool)) | ||
return null; | ||
return (bool)value ? TrueValue : FalseValue; | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, | ||
object parameter, CultureInfo culture) | ||
{ | ||
if (Equals(value, TrueValue)) | ||
return true; | ||
if (Equals(value, FalseValue)) | ||
return false; | ||
return null; | ||
} | ||
} | ||
} |
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
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
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
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