My view has 2 buttons called BrowseButton and UploadButton.
BrowseButton is default and UploadButton is not. My goal is for the default to change after BrowseButton is clicked (ie BrowseButton is not default but UploadButton is).
When BrowseButton is clicked, a Property (string) in my ViewModel is set. This means I can bind to that property and pass the value of that property to my IValueConverter and return either a true or false. This works as desired.
My BoolConverter looks like
public class BoolConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value == null || string.IsNullOrEmpty(System.Convert.ToString(value)))
return false;
return true;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
And my Xaml
<Button Content="Browse for file" Width="150" Margin="5" Command="{Binding BrowseForFileCommand}" IsDefault="{Binding File, Converter={StaticResource BConverter}}" />
<Button Content="Upload" Width="75" Margin="5" Command="{Binding UploadCommand}" IsDefault="{Binding File, Converter={StaticResource BConverter}}" />
The problem is, they both bind to the same BoolConverter class and as such are both equal (ie if one is false then both are false!). Again, I can understand why.
My question is, how do I get around this? Is it really just a case of having multiple Converter classes?
EG
public class BoolConverterForThis : IValueConverter
{//implementation}
public class BoolConverterForThat : IValueConverter
{//implementation}
public class BoolConverterForOther : IValueConverter
{//implementation}