WPF '' local '' - undeclared prefix
I am starting with WPF. I am doing SofiaCarRental tutorial and I have a problem with the "local" alias. Can anyone help me with this alias? I have all these classes not found.
List of errors
Error 3 ''local' is an undeclared prefix. Line 1, position 2.' XML is not valid. c:\..\SofiaCarRental.WPF\Views\AddEditWindow.xaml 1 2 SofiaCarRental.WPF
Error 5 The attachable property 'Resources' was not found in type 'Window'. c:\..\SofiaCarRental.WPF\Views\AddEditWindow.xaml 8 6 SofiaCarRental.WPF
Error 2 The name "NullableBooleanConverter" does not exist in the namespace "clr-namespace:SofiaCarRental.WPF.Views". c:\..\SofiaCarRental.WPF\Views\MainWindow.xaml 10 9 SofiaCarRental.WPF
Error 1 The namespace prefix "local" is not defined. c:\..\SofiaCarRental.WPF\Views\AddEditWindow.xaml 1 1 SofiaCarRental.WPF
Error 4 The type 'local:BaseDialogWindow' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built. c:\..\SofiaCarRental.WPF\Views\AddEditWindow.xaml 1 2 SofiaCarRental.WPF
Error 8 The type 'local:EmptyStringConverter' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built. c:\..\SofiaCarRental.WPF\Views\AddEditWindow.xaml 11 10 SofiaCarRental.WPF
Error 6 The type 'local:NullableBooleanConverter' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built. c:\..\SofiaCarRental.WPF\Views\AddEditWindow.xaml 9 10 SofiaCarRental.WPF
Error 7 The type 'local:YearConverter' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built. c:\..\SofiaCarRental.WPF\Views\AddEditWindow.xaml 10 10 SofiaCarRental.WPF
Main window (I specified "local" here)
<Window x:Class="SofiaCarRental.WPF.Views.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
xmlns:local ="clr-namespace:SofiaCarRental.WPF.Views"
Title="Sofia Car Rental"
Height="720" Width="1280"
MinHeight="720" MinWidth="1280">
<Window.Resources>
<local:NullableBooleanConverter x:Key="booleanConverter" />
<Style x:Key="checkBoxColStyle" TargetType="telerik:GridViewCell">
<Setter Property="HorizontalContentAlignment" Value="Center" />
</Style>
</Window.Resources>
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto">
...
</Grid></Window>
AddEditWindow
<local:BaseDialogWindow x:Class="SofiaCarRental.WPF.Views.AddEditWindow"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="AddEditWindow"
Height="417" Width="383"
Title="{Binding Path=Title}">
<Window.Resources>
<local:NullableBooleanConverter x:Key="booleanConverter" />
<local:YearConverter x:Key="yearConverter" />
<local:EmptyStringConverter x:Key="emptyStringConverter" />
</Window.Resources>
<Grid Margin="20,10,50,10">
...
</Grid></local:BaseDialogWindow>
BaseDialogWindow class:
namespace SofiaCarRental.WPF.Views
{
public class BaseDialogWindow : Window
{
public BaseDialogWindow()
{
this.Owner = App.Current.MainWindow;
this.ShowInTaskbar = false;
this.ResizeMode = System.Windows.ResizeMode.NoResize;
this.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
}
}}
NullableBooleanConverter
namespace SofiaCarRental.WPF.Views{
public class NullableBooleanConverter : IValueConverter
{
public object Convert(object value, Type targetType,
object parameter, CultureInfo culture)
{
object result = this.NullableBooleanToFalse(value);
return result;
}
public object ConvertBack(object value, Type targetType,
object parameter, CultureInfo culture)
{
object result = this.NullableBooleanToFalse(value);
return result;
}
private object NullableBooleanToFalse(object value)
{
if (value == null)
{
return false;
}
else
{
return value;
}
}
}}
source to share
Error 3 'local' - undeclared prefix. Line 1, position 2. 'XML is invalid. c: .. \ SofiaCarRental.WPF \ Views \ AddEditWindow.xaml 1 2 SofiaCarRental.WPF
The AddEditWindow.xaml
prefix is local
not declared in the file . XML namespace declarations operate on a file-by-file basis. They are not inherited and only active for the current file. If you want to use components from other namespaces in this file, you will have to add a declaration there as well. You can see them as using
in the code - whenever you want to use a type, you must tell the compiler where to look in the first place:
<local:BaseDialogWindow x:Class="SofiaCarRental.WPF.Views.AddEditWindow"
…
xmlns:local="clr-namespace:SofiaCarRental.WPF.Views"
… >
Error 5 The "Resources" property that can be connected was not found in the "Window" window. c: .. \ SofiaCarRental.WPF \ Views \ AddEditWindow.xaml 8 6 SofiaCarRental.WPF
While it local:BaseDialogWindow
is a subtype Window
, this is still the type for this file. The compiler sees this when it looks at the XAML for this part:
<SomeType …>
<OtherType.Property>…</OtherType.Property>
</SomeType>
And it is essentially equivalent to this:
<SomeType … OtherType.Property="…" />
Since it is OtherType
not the same as SomeType
, this is an attached property in XAML. But it Window
doesn't have an attached property called Resources
.
Instead, you need to set a property on Resources
your window instead . And your window type SomeType
, so you need to write it like this:
<SomeType …>
<SomeType.Property>…</SomeType.Property>
</SomeType>
So, in your case, you want to set up your resources like this:
<local:BaseDialogWindow x:Class="SofiaCarRental.WPF.Views.AddEditWindow"
… >
<local:BaseDialogWindow.Resources>
…
</local:BaseDialogWindow.Resources>
…
</local:BaseDialogWindow>
The rest of the errors are all because you are using a prefix local:
without declaring it first and the compiler is not finding your types.
source to share