Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
new string has content to bool converter
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuki-Codes committed Mar 3, 2023
1 parent 8424c0f commit 7572ad2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
22 changes: 22 additions & 0 deletions Converters/StringHasContentToBoolConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// © XIV-Tools.
// Licensed under the MIT license.

namespace XivToolsWpf.Converters;

using System;
using System.Windows.Data;

[ValueConversion(typeof(string), typeof(bool))]
public class StringHasContentToBoolConverter : IValueConverter
{
public object Convert(object? value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
string? val = value as string;
return !string.IsNullOrEmpty(val);
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
1 change: 1 addition & 0 deletions Styles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@

<!-- Custom converters -->
<converters:StringHasContentToVisibilityConverter x:Key="StringHasContentToVisibility" />
<converters:StringHasContentToBoolConverter x:Key="StringHasContentToBool" />
<converters:NotNullToVisibilityConverter x:Key="NotNullToVisibilityConverter" />
<converters:NotEmptyToVisibilityConverter x:Key="NotEmptyToVisibilityConverter" />
<converters:IsEmptyToVisibilityConverter x:Key="IsEmptyToVisibilityConverter" />
Expand Down
3 changes: 1 addition & 2 deletions Styles/MenuStyles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
xmlns:local="clr-namespace:XivToolsWpf">

<converters:IconConverter x:Key="StringToIconConveter" />
<converters:StringHasContentToVisibilityConverter x:Key="StringHasContentConverter" />

<Style
x:Key="XivToolsMenuItem"
Expand Down Expand Up @@ -109,7 +108,7 @@
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
Text="{TemplateBinding InputGestureText}"
Visibility="{TemplateBinding InputGestureText,
Converter={StaticResource StringHasContentConverter}}" />
Converter={StaticResource StringHasContentToVisibility}}" />
</Grid>
<Grid
x:Name="SubBlock"
Expand Down

0 comments on commit 7572ad2

Please sign in to comment.