My xaml goes like this:
<DataGrid.Resources>
<Helpers:EnumHelper x:Key="EnumHelper" />
</DataGrid.Resources>
And my class is defined like this:
namespace MyProj.View.UserControlHelpers {
public class EnumHelper { }
}
The error I get is this:
The name "EnumHelper" does not exist in the namespace "clr-namespace:MyProj.View.UserControlHelpers".
I've cleaned this project from the studio, then I've deleted every file in bin and obj subdirectories, I've even changed class name, still without success - I'm still getting this error.
EDIT:
My xaml headers are lik this:
<UserControl x:Class="MyProj.View.Partials.TableWindow.Columns"
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:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:cmd="http://www.galasoft.ch/mvvmlight"
xmlns:Helpers="clr-namespace:MyProj.View.UserControlHelpers"
xmlns:Model="clr-namespace:MyProj.Model"
xmlns:ModelHelpers="clr-namespace:MyProj.Model.Helpers"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
Your class namespace is
MadMin.View.UserControlHelpers
but you refer to it in xaml as
MyProj.View.UserControlHelpers
Related
Hello i have this Viw in XAML
<local:JedenViewBase x:Class="Firma.View.FakturaView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Firma.View"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources>
<ResourceDictionary Source="MainWindowResource.xaml" />
</UserControl.Resources>
<Grid>
.....
</Grid>
</local:JedenViewBase>
And that is class this view
namespace Firma.View
{
public partial class FakturaView : JedenViewBase
{
public FakturaView()
{
InitializeComponent();
}
}
}
And that is JedenViewBase class
namespace Firma.View
{
public class JedenViewBase : UserControl
{
static JedenViewBase()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(JedenViewBase), new FrameworkPropertyMetadata(typeof(JedenViewBase)));
}
}
}
I have problem because view in XAML dont display, i dont know why? JedenViewBase class inherits from UserControl. When i UserControl in view everything works. What i should do?
<UserControl x:Class="Firma.View.FakturaView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Firma.View"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources>
<ResourceDictionary Source="MainWindowResource.xaml" />
</UserControl.Resources>
<Grid>
...
</Grid>
</UserControl>
View FakutraView when i use UserControl
I try rebuild app etc. and i still have problem
You've created a custom control.
That's unlikely to be a good idea and this should probably just be a user control.
The reason you get no view is this.
static JedenViewBase()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(JedenViewBase), new FrameworkPropertyMetadata(typeof(JedenViewBase)));
}
I recommend you remove that. Change
<local:JedenViewBase
To user control.
Make this just a user control.
Alternatively. Read up on custom controls. Put your ui definition in generic xaml.
I also wonder why this has it's own resources. They will be in memory for each instance. If whatever is in that resource dictionary is unique to this control maybe that's not a bad idea. in which case the naming seems strange.
Using VS 2019. I'm surprised the name of a markup extension can be abbreviated as visible in this code which compiles and runs correctly.
In assembly CustMarkExt, I define the markup extension type as MyExtension:
using System.Windows.Markup;
namespace CustMarkExt {
public class MyExtension : MarkupExtension {
public override object ProvideValue (IServiceProvider serviceProvider) {
return "42/42";
}
}
}
In assembly TestMyExtension I refer to it as My (instead of expected MyExtension):
<Window x:Class="TestMyExtension.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:TestMyExtension"
xmlns:myex="clr-namespace:CustMarkExt;assembly=CustMarkExt"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<TextBlock Text="{myex:My}" />
</Grid>
</Window>
To run the code two references are to be added:
add reference to system.xaml in the extension assembly
add reference to the extension in the other assembly
So what doesn't that mean? It doesn't seems to be a bug.
I'm defining an application resource in my app that stores my ViewModels with a navigation element to navigate pages. This is working fine in the xaml editor of visual studio since all the data bindings are working there. However when I try to run the application in debugger it trows an Exception with the message Cannot find source with the name ViewModelLocator. Does anyone know what is going wrong?
I have a local resource defined in my App.xaml like this:
<Application.Resources>
<viewmodel:ViewModelLocator x:Key="ViewModelLocator"/>
</Application.Resources>
Which i try to use like this:
<Page x:Class="QardPrint.PageEmployeesList"
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:QardPrint"
xmlns:viewmodel="clr-namespace:QardPrint.ViewModel"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
Title="PageEmployeesList"
DataContext="{Binding EmployeesListViewModel, Source={StaticResource ViewModelLocator}}">
My ViewModelLocator class looks like this
public class ViewModelLocator
{
public EmployeesListViewModel EmployeesListViewModel => new EmployeesListViewModel(App.Navigation);
}
Try to use ResourceDictionary:
App.xaml:
<Application xmlns:viewmodel="clr-namespace:QardPrint.ViewModel">
<Application.Resources>
<ResourceDictionary>
<viewmodel:ViewModelLocator x:Key="Locator" />
QardPrint.PageEmployeesLis.Xaml:
<Page x:Class="QardPrint.PageEmployeesList"
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:QardPrint"
xmlns:viewmodel="clr-namespace:QardPrint.ViewModel"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
Title="PageEmployeesList"
DataContext="{Binding EmployeesListViewModel, Source={StaticResource Locator}}">
I Found the problem. It was in the App.xaml I deleted the startup parameter. After adding it again the problem was solved.
I did this because I made another window in the startup function of app.cs. But this is probably bad design anyway so going to figure out how to do it better.
I've properly changed the namespaces of my xaml page, but somehow VS not getting the namespace. I tried to do it in the way others have suggested, still getting this error,
"The name "LayoutAwarePage" does not exist in the namespace "using:Inventory.Common".
<common:LayoutAwarePage
x:Name="pageRoot"
x:Class="Inventory.MainPage"
DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Inventory"
xmlns:common="using:Inventory.Common"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
My Main page extends from LayoutAwarePage, this xaml is inside the Common Folder. And the project name is Inventory.
All, I have a user control. In the XAML markup for this control I want to define a resource (instatiate an object called cellColorConverter of the class CellColorConverter which is defined in the same namespace as the control. I have
<UserControl x:Class="ResourceStudio.Resource.Resource"
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"
mc:Ignorable="d" Height="331.2" Width="340">
<UserControl.Resources>
<ResourceStudio.Resource:CellColorConverter x:Key ="cellColorConverter"/> // <- Error.
</UserControl.Resources>
This is giving a compile-time error saying
The namespace prefix ResourceStudio.Res is not defined.
What am I doing wrong here?
Thanks for your time.
Update: I now have
xmlns:local="clr-namespace:ResourceStudio.Resource;assembly=ResourceStudio"
mc:Ignorable="d" Height="331.2" Width="340">
<UserControl.Resources>
<local:CellColorConverter x:Key ="cellColorConverter"/>
</UserControl.Resources>
The CellColorConverter class is in the name space ResourceStudio.Resource, defined as
namespace ResourceStudio.Resource
{
public class CellColorConverter : IMultiValueConverter
{
// ...
}
}
I still get the following error
The name "CellColorConverter" does not exist in the namespace "clr-namespace:ResourceStudio.Resource;assembly=ResourceStudio". F:\Camus\ResourceStudio\ResourceStudio\ResourceStudio\Resource\Resource.xaml
In the XAML:
<ResourceStudio.Resource:CellColorConverter />
The ResourceStudio.Resource is an XML namespace for CellColorConverter.
You need to map this XML namespace to a .NET namespace:
<UserControl xmlns:ResourceStudio.Resource="clr-namespace:ResourceStudio.Resource;assembly=ResourceStudio" ... />
The actual namespace and assembly name depend upon what you've called them in your code.
This article provides more information.
Also, you can make the namespace shorter:
xmlns:local="clr-namespace:..."
<local:CellColorConverter ... >