Reputation: 6227
I got an error on my LoginView, of type XML parse exception. So I checked the inner error details and it tells me a visibility converter resource can't be found.
The complete error:
"{"Cannot find resource named 'BoolToNonVisibilityConverter'. Resource names are case sensitive."}"
I understand from this that the xml parser can't find the converter class. But I checked the namespaces and reference, and all seems to be fine besides.
I'm thinking maybe the resource can't be found as the Visibility binding is set on the UserControl, before the resource declaration. This answer did provide some detail on that.
Does anyone know why the resource isn't being found at run time?
This is the LoginView definition, containing the BoolToNonVisibilityConverter resource reference:
<UserControl x:Class="MongoDBApp.Views.LoginView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:btv="clr-namespace:MongoDBApp.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:pass_helper="clr-namespace:MongoDBApp.Helpers"
Visibility="{Binding LoggedIn,
Converter={StaticResource BoolToNonVisibilityConverter}}"
d:DesignHeight="300"
d:DesignWidth="300"
mc:Ignorable="d">
<UserControl.Resources>
<btv:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
<btv:BoolToNonVisibilityConverter x:Key="BoolToNonVisibilityConverter" />
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="2*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="4*" />
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<GroupBox Name="groupBox3"
Grid.RowSpan="7"
Grid.ColumnSpan="5"
Width="250"
Height="250"
Header="Login">
<Grid>
<Button Name="LoginWithWidget"
Width="102"
Height="22"
Margin="68,126,71,70"
Command="{Binding LoginCommand}"
Content="Login" />
<TextBox Name="UserTextBox"
Width="94"
Height="23"
Margin="119,24,0,171"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Text="{Binding User}" />
<Label Name="label1"
Height="28"
Margin="34,24,0,166"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Content="Username" />
<Label Name="label2"
Height="28"
Margin="34,64,0,126"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Content="Password" />
</Grid>
</GroupBox>
</Grid>
</UserControl>
Upvotes: 0
Views: 153
Reputation: 1524
The UserControl element will be parsed before its child elements and at that point the btv:BoolToNonVisibilityConverter is unknown (hence the run time exception). You have two options i know of:
public SomeUserControl()
{
//Add your resource here before InitializeComponent parse the xaml.
InitializeComponent();
}
Keep in mind xaml defined resource dictionaries will override any resource dictionaries defined before the InitializeComponents.
Upvotes: 1