Please help me, i am new to WP7 development.I have a class like this in code behind page(.xaml.cs):
public class NullVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value == null ? Visibility.Collapsed : Visibility.Visible;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
Visibility? v = value as Visibility?;
return ((v.HasValue) || (v.Value == Visibility.Collapsed)) ? null : "";
}
}
I have a .xaml file is like this:
<ListBox ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled" x:Name="lstImages" HorizontalAlignment="Center" ItemsSource="ImageList" Padding="0" Margin="0" BorderThickness="0" >
<ListBox.ItemTemplate>
<DataTemplate>
<Image x:Name="imgSe" Visibility="{Binding Default, Converter={StaticResource NullVisibilityConverter}}" Height="50" Source="../Assets/g1.png"></Image>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
So Default is a class in ImageList(IList), So if Default is Null then i have to hide the Image and if Default is not null then i have to show that image. I have tried the above code but my app is crashing. I am getting warning as “the resource NullVisibilityConverter could not be resolved” in .xaml page.
Thanks in advance.
You need to create an instance of your value converter within your page resources as follows. Note, the use of xmlns which maps your C# namespace to an XML namespace:
Now reference it as follows, note the conv prefix defined above: