XAML not getting namespace - c#

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.

Related

WPF Can't find local resource when executed

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.

VSIX CS0426 The type name Views does not exist in the type 'ABC'

I'm creating a VSIX plug-in and just added a WPF control like this:
<UserControl x:Class="ABC.Views.Configuration.MyControl"
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:ABC.Views.Configuration"
mc:Ignorable="d"
Loaded="UserControl_Loaded"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
</Grid>
</UserControl>
When I compile the project I am getting the error:
CS0426 The type name Views does not exist in the type 'ABC'
I've checked the projects' default namespace and other relevant configurations and everything looks good. In fact, I have other User Controls in the same directory that are compiling just fine.
What am I doing wrong?
The root cause of this problem was this line in XAML above:
Loaded="UserControl_Loaded"
For some reason VSIX doesn't like wiring events in XAML. I simply removed this and wired it up in Code-behind

XAML can't see a class

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

UserControl content can't be set more than once

having some troubles with UserControl. I cannot get rid of "Content is set more than once error"
From what I've read, the common cause is that .. well, content is set more than once. For example having more than one child or setting content via Content=".." and then specifying another content between the tags.
However, this is UserControl generated by VisualStudio and I made no changes to the xaml.
<UserControl x:Class="TMEGadget.View.Toolbox"
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"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
</Grid>
</UserControl>
Got any tips?
P.S: Can anyone tell me why, when I try to type "Hey,\n\nSome text...", the "Hey,\n\n" is deleted?
Edit: Restarting VS fixed the problem , thanks #Bolu

Can't access Windows 8 Store user control from code

I'm writing a Windows 8 Store application and within that I've designed my own user control.
Here is the code for my usercontrol (This is a dummy control but the problem exists with this):
<UserControl
x:Class="Windows8StoreTest.TestUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows8StoreTest"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Width="70"
Height="40">
<StackPanel>
<Button Content="Hello" Foreground="Pink" BorderBrush="Pink"/>
</StackPanel>
</UserControl>
I've dropped the user control onto my page and give it a name:
<Page
x:Class="Windows8StoreTest.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows8StoreTest"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<local:TestUserControl Name="testControl"/>
</Grid>
</Page>
However, when I go to the code behind I can't access the control by that name. It doesn't seem to exist! What is weird is that the control doesn't exists within InitializeComponent() method for the MainPage class which will be why it does exist.
What am I missing from my user control?
I'm using Windows 8 Store, XAML, c#.
Thanks in advance
Try to use this:
<local:TestUserControl x:Name="testControl"/>
Should work...
hello i don't know what is wrong but it should work.i have just made a sample example of it..i am putting it here hope you have done the same way.
<Page
x:Class="App12.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App12"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<local:MyUserControl1 x:Name="hellousercontrol" />
</Grid>
in my mainpage.cs.. i have just use it like this..
public MainPage()
{
this.InitializeComponent();
hellousercontrol.Height = 100;
}
one more this..have build your solution ?
I had the same issue in c++ environment. I observed, I didn't had default constructor in my class, as soon as I added the default constructor, I could use the defined UserControl in my project through XAML file. However without default constructor I was able to use it from within c++ code.

Categories

Resources