Have a little problem with connecting my class to xamlpage... VS text me that program can't see namespace
but i have another class at this folder which one is working normaly
and i want to show you a block of code of xaml page
<Page x:Class="ClinicApp.XamlPages.ListOfPatientsPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:ClinicApp.XamlPages"
xmlns:localModels="clr-namespace:ClinicApp.EntityModels"
xmlns:local1="clr-namespace:ClinicApp.HelperClasses"
mc:Ignorable="d"
d:DesignHeight="300" Width="1200"
Title="ListOfPatientsPage" Loaded="Page_Loaded" x:Name="page" Background="White">
<Page.Resources>
<local:EnumDescriptionConverter x:Key="EnumDescriptionConverter"/>
<local:AgeConverter x:Key="AgeConverter" />
</Page.Resources>
this one is not working and shows error
local:AgeConverter x:Key="AgeConverter"
this error is at the beginning of the question
also i can show you working class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ClinicApp.EntityModels;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Data;
using System.Reflection;
using System.ComponentModel;
using System.Globalization;
namespace ClinicApp.XamlPages
{
//takes descriprion from gender and requestType enums and place is in datagrid
//instead of showing the real values
public class EnumDescriptionConverter : IValueConverter
{
private string GetEnumDescription(Enum enumObj)
{
FieldInfo fieldInfo = enumObj.GetType().GetField(enumObj.ToString());
object[] attribArray = fieldInfo.GetCustomAttributes(false);
if (attribArray.Length == 0)
{
return enumObj.ToString();
}
else
{
DescriptionAttribute attrib = attribArray[0] as DescriptionAttribute;
return attrib.Description;
}
}
object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
Enum myEnum = (Enum)value;
string description = GetEnumDescription(myEnum);
return description;
}
object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return string.Empty;
}
}
}
I can't understand why he complains about namespaces Sorry if this question is stupid... I am just trying to understand wpf
In the file EnumDescriptionConverter.cs you probably made a mistake in the namespace (it is ClinicApp.XamlPages
instead of ClinicApp.HelperClasses
).
local is defined as xmlns:local="clr-namespace:ClinicApp.XamlPages"
so it works.
I am guessing that AgeConverter is in another namespace (ClinicApp.HelperClasses
) so it shoul be used like this : <local1:AgeConverter x:Key="AgeConverter" />
Just fix the namespace in EnumDescriptionConverter.cs and use local1 (you should probably rename it as helperClasses) and it should work.