How to fix this error?
Error 1 XAML Namespace
http://schemas.microsoft.com/winfx/2006/xaml
is not resolved.
<ResourceDictionary
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
xmlns:dataControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm.Toolkit"
xmlns:appControls="clr-namespace:BusinessApplication1.Controls"
xmlns:loginWindow="clr-namespace:BusinessApplication1.LoginUI"
xmlns:dataInput="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.Input"
>
Here is a person who had a similar problem. They resolved the problem. Let me know if this helps:
http://www.techques.com/question/1-4250198/XAML-Namespace-http:--schemas.microsoft.com-winfx-2006-xaml-is-not-resolved
Here is the relevant quote from the article:
(it) relates to Blend removing an attribute and breaking your XAML. It removes (or forgets to add) the mc:Ignorable="d" attribute to UserControls.
Related
I am working on making a separate set of views for mobile devices, rather than using additional adaptive UI states for the phone. I am able to achieve this by adding a sub-folder in my Views folder called DeviceFamily-Mobile and adding a new View with the same name as the one I am overriding.
I have the following View that will work and display "MOBILE" on a mobile device/emulator.
<Page x:Class="MyApp.PayeesPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:behaviors="using:Template10.Behaviors"
xmlns:controls="using:Template10.Controls"
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:models="using:MyApp.Models"
xmlns:viewModels="using:MyApp.ViewModels"
xmlns:views="using:MyApp.Views"
mc:Ignorable="d">
<RelativePanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<TextBlock x:Name="MobileTextBlock"
Foreground="{ThemeResource ForegroundColorBrush}"
Text="MOBILE" />
</RelativePanel>
</Page>
However, if I try to set the DataContext to allow me to actual display something useful, like so:
<Page.DataContext>
<viewModels:PayeesPageViewModel x:Name="ViewModel" />
</Page.DataContext>
Then I get an error when navigating to the PayeesPage:
Unable to cast object of type 'Windows.UI.Xaml.Controls.TextBlock' to type 'MyApp.ViewModels.PayeesPageViewModel'.
This is the same way I set the DataContext on the original PayeesPage and it works fine. Is there a different way to set the DataContext on these alternate Views, or am I missing something?
It turns out that the mobile View needs to have the same x:Class as the original Page. ReSharper was complaining when I tried to call it MyApp.Views.PayeesPage because that already existed, so I changed it to MyApp.PayeesPage. However, when I switched it back so that both were using the same x:Class then everything started working as expected.
Unfortunately, I am getting a bunch of red squigglies from ReSharper, but things are working as they should be. Just in case anyone comes across this question in the future:
Views/PayeesPage.xaml:
<Page x:Class="MyApp.Views.PayeesPage"
...>
Views/DeviceFamily-Mobile/PayeesPage.xaml:
<Page x:Class="MyApp.Views.PayeesPage"
...>
I have a CustomControl derived class in a dll (MyNamespace.UI). How can I use this control in my main application? I've tried adding a reference to the project and then using a custom XAML namespace to point to my namespace, but it can't find it:
<Page ...
xmlns:ui="using:MyNamespace.UI"
...>
<Canvas>
<ui:MyControl />
</Canvas>
</Page>
I get an error:
The name "MyControl" does not exist in the namespace "using:MyNamespace.UI".
Searching around, I managed to find the following quote:
The name of the assembly that defines the backing types for a XAML
namespace is not specified in the mapping. The logic for which
assemblies are available is controlled at the app-definition level and
is part of basic app deployment and security principles. Declare any
assembly that you want included as a code-definition source for XAML
as a dependent assembly in project settings.
http://msdn.microsoft.com/en-gb/library/windows/apps/jj150588.aspx
Can someone point me in the direction of the "dependent assembly" setting in the project settings?
Edit After making sure the root namespace project setting matched the namespace of my control (MyNamespace.UI) I could get the project to compile. But I can't get it to run because I get loads of crashes with the following information:
WinRT information: Cannot create instance of type 'MyNamespace.UI.MyControl' [Line: 44 Position: 37]
No information on why it couldn't make the control though... I stepped through the constructor of MyControl and the exception is thrown in InitializeComponent(). This is the XAML of my UserControl (MyControl):
<UserControl
x:Class="MyNamespace.UI.MyControl"
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"
d:DesignHeight="300"
d:DesignWidth="400">
<Grid>
</Grid>
</UserControl>
Edit 2 I deleted the Grid control, built and ran, and it worked, so then I put the Grid control back, and it still worked. Very weird.
You need to make sure the MyNamespace.UI assembly has a RootNamespace property that matches MyNamespace.UI. This property can't be changed in the project settings pages, but you can do it via notepad or equivalent. My RootNamespace was set to UI, and when I changed it, it started working.
The situation:
"Shell" project with App.xaml and a resource dictionary in Styles/Default.xaml with the interesting parts thus:
Default.xmal
<ResourceDictionary
<Style x:Key="StandardTextBox" TargetType="TextBox">
...
</Style>
</ResourceDictionary
App.xaml
<Application>
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Styles/Default.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
In a module project I've got a form with:
<TextBox Style="{StaticResource StandardTextBox}" />
At runtime I get the infamous "Error HRESULT E_FAIL has been returned from a call to a COM component." exception. The funny thing is during design time, in VS, the style is applied just fine in design mode. (and how VS.Net works the magic of knowing there's a resource in App.xaml in the Shell project - which is not referenced by the module project AT ALL - is baffling ... but I digress)
My overall goal is to have resources defined in files separate from App.xaml, in the Shell project, and have the styles applied intrinsically across the Module projects.
Update: Yeah, I was totally on the wrong war path here. The TextBox style that Blend generates references another style for the ValidationToolTip. Failing to include that will cause the issue described above. Unfortunately the error message was quite unhelpful and the squiggle underline in VS is easily missed when it's deep in the middle of the XAML definition and way off to the right. Live and learn.
The real issue was not including another referenced style. See this.
So I've been trying for some time to get theming to work in Silverlight 4.
I've added a reference to System.Windows.Controls.Theming.Toolkit and System.Windows.controls.Theming.ShinyRed
Then I went and did something like this:
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dataInput="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.Input" xmlns:WebbyDraw="clr-namespace:WebbyDraw" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" x:Class="SilverlightApplication1.MainPage"
Width="960" Height="700" mc:Ignorable="d"
xmlns:shinyRed="clr-namespace:System.Windows.Controls.Theming;assembly=System.Windows.Controls.Theming.ShinyRed" >
<shinyRed:ShinyRedTheme>
<Grid x:Name="LayoutRoot2">
....
</Grid>
</shinyRed:ShinyRedTheme>
</UserControl>
But I always get the same old theme...no errors, but nothing happens either. I've also tried other themes from the Silverlight 4 toolkit, and also tried applying it to a single control...nothing...what am I doing wrong? I've read several tutorials and haven't found the answer.
This is how i use theming, i also allow my users to change to their preferred theme -
you can replace ShinyRed.xaml with any other style resource file to support multiple themes can also be done programmatically(remove one resource dictionary and add another).
In your user control xmal
xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
<toolkit:Theme x:Name="ThemeContainer">
<Grid x:Name="LayoutRoot">
... all other controls in the page
</Grid>
Copy all brushes and fonts required for the shinyred theme and create one single Style file called ShinyRed.xaml (you can simply follow the includes in each file to get it all in one file)
So in your App.xaml reference this newly created xaml adn that is it compile and run!
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Assets/ShinyRed.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Suppose I have a top-level ResourceDictionary element in a XAML file with no C# code-behind. How can I put this element in a specific namespace?
I'm not sure if you can -- but I've never seen this done.
What I have seen is putting ResourceDictionary XAML files in a directory structure in an assembly, and getting it via the Pack URI syntax.
Dr. WPF has an interesting post on getting ResourceDictionaries in code here.
It is much simpler than I had thought:
<ResourceDictionary x:Class="SomeNamespace.SomeClassName"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
</ResourceDictionary>