I have the following in vb:
Namespace WpfSample
Class MainWindow
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
End Class
Public Class BooleanToVisibilityConverter
Implements IValueConverter
Public Sub New()
End Sub
Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IValueConverter.Convert
If value.Equals(True) Then
Return System.Windows.Visibility.Visible
Else
Return System.Windows.Visibility.Collapsed
End If
End Function
Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
If value.Equals(System.Windows.Visibility.Visible) Then
Return True
Else
Return False
End If
End Function
End Class
End Namespace
then my XAML looks like:
<Window x:Class="WpfSample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:l="clr-namespace:WpfSample"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<l:BooleanToVisibilityConverter x:Key="converter" />
</Window.Resources>
<Grid>
<TextBox x:Name="txtName" HorizontalAlignment="Left" Height="23" Margin="112,37,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
<Label x:Name="lblLabel" Content="{Binding Text, ElementName=txtName,UpdateSourceTrigger=PropertyChanged}"
Visibility="{Binding IsChecked,ElementName=chkShowLabel, Converter={StaticResource boolToVis}}"
HorizontalAlignment="Left" Margin="256,37,0,0" VerticalAlignment="Top"/>
<CheckBox x:Name="chkShowLabel" Content="Show Label" HorizontalAlignment="Left" Margin="112,65,0,0" VerticalAlignment="Top"/>
</Grid>
</Window>
i am seeing the following 3 errors The name "BooleanToVisibilityConverter" does not exist in the namespace "clr-namespace:WpfSample".
The type 'l:BooleanToVisibilityConverter' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.
The tag 'BooleanToVisibilityConverter' does not exist in XML namespace 'clr-namespace:WpfSample'.
remove the usage of converter from the sample and first build your project. Only after it gets build successfully will you be able to use it in xaml.
Also your key name under Window.resources is "converter" while you are using "boolToVis" in label tag
One more thing which you can do is after building the project by removing the converter usage in xaml, write xmlns:l= . Your full assembly name will appear in the list. This way you can avoid writing incorrect assembly path.