<Window x:Class="Template.MainWindow"
xmlns:System="clr-namespace:System;assembly=mscorlib">
<Grid>
</Grid>
What does xmlns:System="clr-namespace:System;assembly=mscorlib means?
My ideas:
Include System from mscorlib? What about clr-namespace? So I can
use all functionality in mscorlib in Template.MainWindow.xaml.
Thanks for replies
Is the namespace associated to Window tag
namespaces are used to avoid collisions when two different systems use the same tag name.
Refer to Microsoft Documentation about this:
http://msdn.microsoft.com/en-us/library/ms747086.aspx
See the two topics:
The WPF and XAML Namespace Declarations
Mapping to Custom Classes and Assemblies
You will get idea little clear.
Related
How would you make a reference in XAML vs code behind? It seems like mrkup:Class="System.Web.UI.HtmlTextWriterTag" in the following snip would work
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ns.proj"
mrkup:Class="System.Web.UI.HtmlTextWriterTag"
>
...
allowing the following.
<mrkup:hr/>
I still get the undeclared prefix error.
I have tried backing down the tree to System.Web.UI and made sure I was not using a reserved word like html:xx and it still fails. I must be overlooking something basic or seriously missing a XAML/Xamarin.Forms premise.
Update Edit:
Based on Jason and Diego's input:
Intellisense kicked in after typing using xmlns:mrkup="using: resulting in
xmlns:mrkup="clr-namespace:System.Web;assembly=netstandard"
Which is a great start
<mrkup:UI.HtmlTextWriterTag hr=""/>
Fails with mrkup:UI.HtmlTextWriterTag.hr not found in xmlns clr-Namespace:System.Web;assembly=netstandard
Is it possible that .UI is not in System.Web in .NET Standard 2.0?
Update to the Update:
It appears that UI is NOT in System.Web in .NET Standard 2.0. This is from the System.Web.dll in C:\Program Files (x86)\Microsoft SDKs\NuGetPackagesFallback\NETStandard.Library\2.0.1\build\netstandard2.0\ref
Actually, you have to declare the mrkup prefix before use it.
Just like this:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ns.proj"
xmlns:mrkup="clr-namespace:System.Web.UI;assembly:dllName">
...
<mrkup:HtmlTextWriterTag hr="Property Value"/>
...
</ContentPage>
I'm not sure where the namespace ends, so in the snippet above I'm supposing the namespace is System.Web.UI and the class HtmlTextWriterTag and then you have a property hr on it. If the referred namespace is outside the actual project, you have to notice that assembly part of the declaration, but you can ignore it when referring to the class of the same assembly.
You can take a look at the official docs from Microsoft about Declaring Namespaces for Types to get a more detailed information.
I'm trying to use a resource file in my XAML. For some reason i keep getting the error of not finding the type Texts. Not sure what I'm doing wrong here.
XAML
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:CashRegisterApp.Resources"
x:Class="CashRegisterApp.Start">
<ContentPage.Content>
<StackLayout
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" >
<Label Text="{x:Static local:Texts.Start}"/>
</StackLayout>
</ContentPage.Content>
</ContentPage>
RESX
Solution explorer
Creating RESX files within Shared projects is known to cause issues. You can see several lengthy posts in Xamarin Forums regarding this (here and here for example).
The easiest solution that will allow you to use the approach you want is to create a new .NET Standard Library of PCL library in your solution, create your RESX files there and set their visibility to public. Then you will be able to utilize them using the x:Static syntax as expected.
Many developers use an alternative in the form of a custom markup extension like the solution by ClaudioPereira in this forum. This simplifies the syntax even more.
Finally, for most detailed information on Xamarin.Forms you can refer to the official documentation.
I had this issue too and I hope this answer helps people in the future with this issue.
Following this guide taught me how to set up resx files in Xamarin forms.
Their TranslateExtension allows for referring to the resx file directly from Xaml.
Unfortunately, in its raw form it doesn't pick up a runtime change in locales.
This is fixable by changing their "Localize" class (on the native platforms) to keep a reference of the CultureInfo when changed via the SetLocale method and return it when the GetCurrentCultureInfo method is called.
Hi I'm trying to dynamically load xap files with MEF. I've got some bare bones code working with very basic Silverlight xaps. But loading xaps which are based on MVVM light I get a "Cannot find a Resource with the Name/Key Locator" which I guess is related to the host need something from MVVM Light. Can anyone with this? Cheers, Chris.
The error means that you are missing a resource called "Locator", usually being the ViewModelLocator. Look at your view XAML and you should find something like this:
<... DataContext="{Binding SomeViewModel, Source={StaticResource Locator}}" ...>
This line specifies the data context for an element. The data context is bound to the SomeViewModel property of a the static resource named Locator. Usually the locator is defined in the App.config by a statement similar to this:
<prefix:ViewModelLocatorClassName x:key="Locator"/>
The error most likely means that this line is missing.
I have scenario where my loose xaml file can contain the custom control from another assembly. How do i make a reference to that assembly. My Loose XAML and assembly are at the same path.
I know the embedded xaml or xaml with in a project, the reference is added like this:
xmlns:WpfToolKit="http://schemas.microsoft.com/wpf/2008/toolkit"
Now how can i give similar type of reference in the loose xaml file.
Like so:
xmlns:Awesome="clr-namespace:MyAwesomeNameSpace"
And then use your controls as such:
<Awesome:MyAwesomeControl />
For nice looking schemas, please read this article on MSDN:
http://msdn.microsoft.com/en-us/library/ms747086.aspx
You will need the XmlnsDefinitionAttribute definition on your class.
Hope this helps!
ReSharper's complaining about some of my XAML with the following error:
'Name' attribute is not allowed here
because type 'FlashingTextBlock' is
implemented in the same project. Use
'x:Name' instead
What's the problem here? Should I do what it says?
See an excellent explanations in this answer, and decide for your own ;)
In WPF, what are the differences between the x:Name and Name attributes?
Does FlashingTextBlock have a System.Windows.Markup.RuntimeNameProperty attribute?
According to "Windows Presentation Foundation Unleashed" by Adam Nathan:
... you can simply set its Name property to a string rather than use the x:Name syntax. You can use either mechanism, but you can't use both simultaneously.