-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated to latest version with message that shows if fileoptimizer ca…
…n't be found
- Loading branch information
Showing
5 changed files
with
110 additions
and
9 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
75 changes: 75 additions & 0 deletions
75
DeveImageOptimizerWPF/Converters/SwitchBindingExtension.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,75 @@ | ||
using System; | ||
using System.Windows; | ||
using System.Windows.Data; | ||
using System.Windows.Markup; | ||
|
||
namespace DeveImageOptimizerWPF.Converters | ||
{ | ||
public class SwitchBindingExtension : Binding | ||
{ | ||
public SwitchBindingExtension() | ||
{ | ||
Initialize(); | ||
} | ||
|
||
public SwitchBindingExtension(string path) | ||
: base(path) | ||
{ | ||
Initialize(); | ||
} | ||
|
||
public SwitchBindingExtension(string path, object valueIfTrue, object valueIfFalse) | ||
: base(path) | ||
{ | ||
Initialize(); | ||
this.ValueIfTrue = valueIfTrue; | ||
this.ValueIfFalse = valueIfFalse; | ||
} | ||
|
||
private void Initialize() | ||
{ | ||
this.ValueIfTrue = Binding.DoNothing; | ||
this.ValueIfFalse = Binding.DoNothing; | ||
this.Converter = new SwitchConverter(this); | ||
} | ||
|
||
[ConstructorArgument("valueIfTrue")] | ||
public object ValueIfTrue { get; set; } | ||
|
||
[ConstructorArgument("valueIfFalse")] | ||
public object ValueIfFalse { get; set; } | ||
|
||
private class SwitchConverter : IValueConverter | ||
{ | ||
public SwitchConverter(SwitchBindingExtension switchExtension) | ||
{ | ||
_switch = switchExtension; | ||
} | ||
|
||
private SwitchBindingExtension _switch; | ||
|
||
#region IValueConverter Members | ||
|
||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) | ||
{ | ||
try | ||
{ | ||
bool b = System.Convert.ToBoolean(value); | ||
return b ? _switch.ValueIfTrue : _switch.ValueIfFalse; | ||
} | ||
catch | ||
{ | ||
return DependencyProperty.UnsetValue; | ||
} | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) | ||
{ | ||
return Binding.DoNothing; | ||
} | ||
|
||
#endregion | ||
} | ||
|
||
} | ||
} |
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