IValueConverter, xaml problem
-
Hi, I am working with a WPF project and have a string property Address.
StackPanel Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="2" Margin="2,2,10,2" Visibility="{Binding Address, Converter = {StaticResource FormatAddress}}"
The converter FormatAddress is returning Visibility.Visible if Address is !string.Empty and !="". Can I use this converter if I want show the StackPanel if the Address is string.Empty or ""? Or do I have to create a new converter for this case? Regards Olof
-
Hi, I am working with a WPF project and have a string property Address.
StackPanel Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="2" Margin="2,2,10,2" Visibility="{Binding Address, Converter = {StaticResource FormatAddress}}"
The converter FormatAddress is returning Visibility.Visible if Address is !string.Empty and !="". Can I use this converter if I want show the StackPanel if the Address is string.Empty or ""? Or do I have to create a new converter for this case? Regards Olof
Why not just use
string.IsNullOrWhitespace
in the converter to decide whether the string is empty or not?I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be
Forgive your enemies - it messes with their heads
-
Why not just use
string.IsNullOrWhitespace
in the converter to decide whether the string is empty or not?I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be
Forgive your enemies - it messes with their heads
He can, provided he is using .Net 4.0. As far as I remember (from a previous discussion), this does not exist in versions before 4.0.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick Visit the Hindi forum here.
-
He can, provided he is using .Net 4.0. As far as I remember (from a previous discussion), this does not exist in versions before 4.0.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick Visit the Hindi forum here.
True, but it's easy to replicate the logic.
public static bool IsNullOrWhitespace(this string text)
{
if (string.IsNullOrEmpty(text))
return true;
return text.Trim() == string.Empty;
}I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be
Forgive your enemies - it messes with their heads
-
True, but it's easy to replicate the logic.
public static bool IsNullOrWhitespace(this string text)
{
if (string.IsNullOrEmpty(text))
return true;
return text.Trim() == string.Empty;
}I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be
Forgive your enemies - it messes with their heads
-
Hi, I am working with a WPF project and have a string property Address.
StackPanel Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="2" Margin="2,2,10,2" Visibility="{Binding Address, Converter = {StaticResource FormatAddress}}"
The converter FormatAddress is returning Visibility.Visible if Address is !string.Empty and !="". Can I use this converter if I want show the StackPanel if the Address is string.Empty or ""? Or do I have to create a new converter for this case? Regards Olof
Yes. You can just use the same converter. make sure that your converter always returns Visibility type instead null or string.
MVVM devotee :)
-
Hi, I am working with a WPF project and have a string property Address.
StackPanel Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="2" Margin="2,2,10,2" Visibility="{Binding Address, Converter = {StaticResource FormatAddress}}"
The converter FormatAddress is returning Visibility.Visible if Address is !string.Empty and !="". Can I use this converter if I want show the StackPanel if the Address is string.Empty or ""? Or do I have to create a new converter for this case? Regards Olof
You could probably use a trigger. You can set visibility based on the true/false.