I am trying to create my custom control, but I am still getting error: The name "CustomCircleControl" does not exist in the namespace "using:App8"
My app namespace is App8 and class CustomCircleControl exists in it.
Errors appears in file Generic.xaml, but I do not understand why.
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App8">
<Style TargetType="local:CustomCircleControl"> -- This line is marked by visual studio as error (The name "CustomCircleControl" does not exist in the namespace), but intelisence knows class CustomCircleControl.
Thank you for any help :-)
You are declaring the namespace incorrectly.
The correct way to declare a namespace in XAML is the following:
xmlns:MyNamespace="clr-namespace:Your.Namespace.Here"
So in your case, it'll look like this:
xmlns:local="clr-namespace:App8"
Related
This is my first foray into custom controls, and it's not going well. I have a custom graph control derived from Canvas.
namespace Grapher2 {
public class SeriesManager : Canvas {
public SeriesManager() {
...
}
}
}
It's defined in the same project and namespace as my app. I tried adding a reference to the control in XAML as follows:
<Window x:Class="Grapher2.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:graph="clr-namespace:Grapher2"
Title="Grapher" Width="800" Height="600">
<StackPanel Name="container" Width="700" Height="500">
<graph:SeriesManager Name="seriesManager" Width="700" Height="500" />
</StackPanel>
But when I try to reference the control name "seriesManager" in the code-behind for the Window, I get "The name 'seriesManager' does not exist in the current context."
Furthermore, the XAML editor will not render the Window, giving a huge stack trace with the error: "Type 'MS.Internal.Permissions.UserInitiatedNavigationPermission' in Assembly 'PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is not marked as serializable."
I imagine the solution is something stupidly simple for anyone who's done custom controls. But I'm stumped.
did you try x:Name="seriesManager" in your xaml?
Edit: This may not be the issue seeing how you said your xaml isn't rendering. I'm guessing once you get the xaml to render in the designer... the code behind will work better.
Edit 2: Whenever I've had a problem with the designer rendering, it's because I'm doing something in the constructor of my custom control. Check your SeriesManager to see if you are doing something in its constructor that is causing a problem. Maybe you are referencing something that doesn't exist yet. If you do have extra code in your constructor, consider moving it to the UserControl_Loaded event.
Backing up Scott's answer here, since he helped me solve it:
What I did wrong was trying to access the control BEFORE InitializeComponent(), but was confused by 2 other error messages somewhere else in the code.
Just in case someone else has this error.
I am working on a WPF application that uses the Wizard window from the Extended WPF Toolkit. I need to change the color of the footer of the wizard and unfortunately the developers didn't expose any property to do it, so I need to edit the style.
The Toolkit is imported as NuGet package, so I cannot just edit the source code. I found the default style of the control (Generic.xaml) on Codeplex, copied it in a file in my project so now I have something like this:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Xceed.Wpf.Toolkit"
xmlns:conv="clr-namespace:Xceed.Wpf.Toolkit.Core.Converters">
<conv:WizardPageButtonVisibilityConverter x:Key="WizardPageButtonVisibilityConverter" />
<Style TargetType="{x:Type local:Wizard}">
...
Here I get two errors:
The type 'conv:WizardPageButtonVisibilityConverter' was not found.
Verify that you are not missing as assembly reference and that all
referenced assemblies have been built.
and
The name "Wizard" does not exist in the namespace
"clr-namespace:Xceed.Wpf.Toolkit".
Then I tried to change the line
xmlns:local="clr-namespace:Xceed.Wpf.Toolkit"
to
xmlns:local="http://schemas.xceed.com/wpf/xaml/toolkit"
and the second error disappeared, but I don't know how to deal with the first one.
Do you have any idea? Is it the right way to change the default style?
Thanks!
The XAML namespace mapping should also specify the name of the assembly in which the WizardPageButtonVisibilityConverter class is defined:
xmlns:conv="clr-namespace:Xceed.Wpf.Toolkit.Core.Converters;assembly=Xceed.Wpf.Toolkit"
I am new to WPF + MVVM architecture. In my application, I am trying to implement "DataContext" in the XAML itself as below
<Window x:Class="MyWPF.UI.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:MyWPF.UI.ViewModel"
Title="MainWindow" Height="350" Width="525">
<Window.DataContext>
<vm:Northwind_DataViewModel></vm:Northwind_DataViewModel>
</Window.DataContext>
<Grid>
</Grid>
</Window>
I am getting "The name 'Northwind_DataViewModel' does not exists in the namespace 'clr-namespace:MyWPF.UI.ViewModel".
I have ViewModel file. Before using "DataContext", I built this application.
Could you please let me know what is wrong with my code?
thanks
The name 'Northwind_DataViewModel' does not exists in the namespace 'clr-namespace:MyWPF.UI.ViewModel".
Chances are, you compiler is right. There is no class named MyWPF.UI.ViewModel.Northwind_DataViewModel in your project. Make sure it exists, has a public, parameterless constructor, is not an inner class of something and not generic. If that's the case, it will work.
In case namespace is declared in separate assembly from where your XAML resides, you have to provide assembly name as well.
Sample:
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Similarly, provide your assembly name where this namespace resides (Assuming assembly name is MyWPF.UI):
xmlns:vm="clr-namespace:MyWPF.UI.ViewModel;assembly=MyWPF.UI"
Thanks a lot your responses. Finally I got the solution. Actually, this project was placed in a shared folder. So, I moved it to my local drive (C:). Now, it is working fine without any issues.
I guess, in shared path / shared folder, it may not work. Please let me know if I am wrong.
thanks again.
In order to solve this problem, you need to understand how the DataContext works. This answer contains a lot of hints and links to supporting tutorials:
ReSharper WPF error: "Cannot resolve symbol "MyVariable" due to unknown DataContext"
I'm currently trying to use this TextBox AutoComplete custom control :
http://www.codeproject.com/Articles/26535/WPF-Autocomplete-Textbox-Control?msg=3484969#xx3484969xx
This is the first time I'm adding such external things in my project and when I add the header line in my Xaml file like explained in the article :
<UserControl x:Class="Maha.Gestion.Note_de_frais.SaisieNoteDeFrais"
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:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:local="clr-namespace:WPFAutoCompleteTextbox"
>
VisualStudio tell me that clr-namespace is not included in the assembly.
I'm sure this is something totally trivial but after few hours still can't find any solution.
All files asked by the author of the article has been added of course.
Someone can explain me the good way to add such external resources ?
Thanks
xmlns stands for XML NameSpace. It basically links a prefix of your choice to a namespace. In your case, it links the local prefix with the namespace declared in the file that you want to use.
You can find out more by looking at the XAML Namespaces and Namespace Mapping for WPF XAML article at MSDN.
Please check that the file that you want to use has this exact namespace declared.
Please remove all white space from your xmlns declarations - you may have extraneous characters hidden there.
Like this:
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:local="clr-namespace:WPFAutoCompleteTextbox">
I feel like I must be going crazy, but I just changed the name of a property in a view model (a C# file) from Width to Size using Visual Studio's refactor-rename feature. When I was done, this error appeared in the Error window:
Error 2: The property 'Size' does not exist in XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation'.
The error was referring to a XAML UserControl file. When I checked the file to see what was up, I realized that every attribute named Width had been changed to Size.
Example:
<UserControl x:Class="ApbSymbolGenerator.Views.Symbol"
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"
Size="{Binding Size}"
Height="{Binding Size}">
This is the first time I've ever had refactor-rename cause a change to a XAML file (besides the x:class value). (Note: I did not do a global find/replace, I did refactor-rename. I undid everything and performed the rename again, and it did the same thing.)
Strangely, it only affected one of several XAML files in my app that has a Width property.
Any explanation what could be going on here?
Looks like this is a bug (that won't be fixed) - Refactor Rename Bug