c# WPF AlternateContent doesn't exist in the Namespace [...] - c#

I am facing the need to have XAML Code only in design-time. I have found a nice Solution to this, which can be found here. It seems like there are a few guys having a Problem with the parse-timing of XmlnsDefinitionAttribute which is solved here.
In my case the issue is really, that I cannot compile my code, because AlternateContent can't be found in the namespace xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006". I haven't found any documentation to this namespace indeed and it seems strange, that the line mc:Ignorable="d"doesn't fail to build, which means I have at least one assembly containing the above namespace.
This is my Code:
#if DEBUG
[assembly: XmlnsDefinition("debug-mode", "MyNamespace")]
#endif
<Window x:Class="MyNamespace.SomeWindow"
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:debug="debug-mode"
mc:Ignorable="d"
... >
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<mc:AlternateContent>
<mc:Choice Requires="debug">
<ResourceDictionary Source="pack://application:,,,/Styles;component/Generic.xaml" />
</mc:Choice>
</mc:AlternateContent>
...
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
...
</Window>
My guess is, that I'm missing an Assembly-Reference, but I've not yet found a Documentation specifying a containing Assembly for AlternateContent. Do you have any ideas how I might get this to work?
Edit:
It seems like this is a common VS Problem which can be solved by this mc:Ignorable="d mc". This just doesn't work in my case, because I would need this to include Resources at Design-Time, which should be available to the VS-Designer :)

It seems like this is a common VS problem which can be solved by this code
mc:Ignorable="d mc"
This must be added to the root element of the view.
Note: that you already should have mc:Ignorable="d" in your root element, so you have to just add the mc to it.

Related

VisualStudios ERROR MainViewModel doesnt exist

Hy Guys i installed VS three times and everytime the same Error
I installed MVVM Light in the NUGET Manager for the MVVM
After installing i set the DataContext in the Main.Window on MainViewModel
That works now. But in my App.xaml is it not possible to get the Resource Dictonary in it. In attachment screenshots of my problem.
appxaml ( <= Full size image)
and...
Try to declare 'vm' namespace before usage, put it in Application tag.
Replace <vm: with <local: as the "local" namespace is aleady mapped at the root element in App.xaml:
<Application x:Class="testapp.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:testapp.ViewModel"
StartupUri="MainWindow.xaml">
<Application.Resources>
<local:ViewModelLocator x:Key="Locator" />
</Application.Resources>
</Application>

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

Control Does Not Exist in Namespace

I'm attempting to use the MediaUriElement in the custom (WPFMediaKit).
I've added it into the namespace like so;
xmlns:controls="clr-namespace:WPFMediaKit.DirectShow.Controls;assembly=WPFMediaKit"
and then I have tried to access it;
<Grid>
<controls:MediaUriElement x:Name="mediaUriElement" />
</Grid>
however I just get an error: The name MediaUriElement does not exist in this namespace. VS does give me a suggestion to use it when I am typing though;
How can I correctly add this into my project?
I've tried and it is worked. What I've done:
Switched project from Framework 4.5 to Framework 4.0
Added references such as DirectShowLib-2005.dll and WPFMediaKit.dll to the project
Declared xaml namespace xmlns:controls="clr-namespace:WPFMediaKit.DirectShow.Controls;assembly=WPFMediaKit" like that:
<Window x:Class="ExcelExportWpfApplication.MainWindow"
... The code omitted for the brevity...
xmlns:controls="clr-namespace:WPFMediaKit.DirectShow.Controls;assembly=WPFMediaKit"
xmlns:vm="clr-namespace:ExcelExportWpfApplication.ViewModel"
mc:Ignorable="d"
Title="MainWindow" Height="550" Width="525"
WindowStartupLocation="CenterScreen">
And just written in xaml:
<controls:MediaUriElement Grid.Row="2"/>
No errors

The name "ViewModelLocator" does not exist in the namespace "clr-namespace:ComEX.ViewModel"

VS 2013. Trying to learn MVVM and commands in WPF, but I can't see why I am getting this error.
"The name "ViewModelLocator" does not exist in the namespace "clr-namespace:ComEX.ViewModel"."
Solution Explorer
<Application x:Class="ComEX.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:ComEX.ViewModel"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ignore="http://www.galasoft.ch/ignore"
StartupUri="MainWindow.xaml"
mc:Ignorable="d ignore">
<Application.Resources>
<!--Global View Model Locator-->
<vm:ViewModelLocator x:Key="Locator"
d:IsDataSource="True" />
</Application.Resources>
</Application>
There are two workarounds to solve this issue
Try to right click on solution and after that choose in pop up menu "Clean" or "Clean solution" and after that "Rebuild"
If this did not help try second:
Such error also hapens if an exception occurred while creating instances registered in locator by SimpleIoc.Default.Register, so try to fix all errors except locator related and this error will also disapear

Adding x:Name to a user control gives error in generated code of page its used in

I am basically using a user control for the first time, so hopefully it's just a dumb mistake.
I have a simple user control
<UserControl x:Class="TestProject.WebApp.myUserControl"
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"
mc:Ignorable="d"
xmlns:riaControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.DomainServices"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">
<Grid>
<sdk:AutoCompleteBox Name="myACB" ItemsSource="{Binding Data}" FilterMode="StartsWith" MinimumPrefixLength="2" >
</sdk:AutoCompleteBox>
</Grid>
</UserControl>
I am using the control in another page (in a stack panel):
<navigation:Page x:Class="TestProject.WebApp.myPageView"
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"
mc:Ignorable="d"
xmlns:local="clr-namespace:TestProject.WebApp"
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation">
<Grid>
<StackPanel Orientation="Horizontal">
<local:myUserControl x:Name="myUC" />
</StackPanel>
</Grid>
</navigation:Page>
The control is in the same namespace as page. Removing the x:Name allows the project to compile and the control functionally works. When x:Name is specified I get an error in the generated code of the page:
Type 'TestProject.WebApp.myUserControl' is not defined.
It happens on these lines of code:
internal TestProject.WebApp.myUserControl myUC;
this.myUC == (TestProject.WebApp.myUserControl)this.FindName("myUC")
I tried with two different controls. Same thing. The generated code has "using TestProject.WebApp;" so I don't know why there is an error only when I have a named instance of the control.
I also cannot seem to use just the Name property. I even tried overloading the NameProperty in the control.
I was able to find a post about this here:
.g.vb file claims that Type X is not defined, even though it is!
Apparently, there is an issue when a project has a service reference (in my case I am using RIA services) and the user control resides in an assembly with the same root namespace as the one you are trying to use it in.
So for me it was,
TestProject.WebApp
Then I tried creating a new project for just the control
TestProject.Controls
Same problem.
Then, when I renamed the project and changed the namespace to
CustomControls
it worked.
Hopefully this saves someone else from some frustration and I really hope this problem can be fixed by MS soon.
What you are showing here should work. What is the default namespace in your project property's? Also did you rename your user control after you created it. Both of those issues could be causing you problems.

Categories

Resources