After reading MSDN-XAML Namespaces and MSDN-Understanding XAML Namespaces, I still do not understand the purpose of having a Qualified Name (QName).
Take the following namespace declaration as an example:
xmlns:x='http://www.w3.org/1999/XSL/Transform'
x is the prefix short for the full URI (in this case, an URL) : http://www.w3.org/1999/XSL/Transform. Then there is this QName called xmlns. The definition for QName in mdsn is:
This complete name including the prefix is the lexical form of a
qualified name (QName):
What's that supposed to mean and why is it there since thet statement already has a locator and a prefix to identify the namespace and its names to be used?
I think more than this being an XAML question it is just an XML namespace question.
The xmlns attribute (a special attribute) is just the attribute used in XML to define a namespace. It says "here comes a namespace declaration". If you do not add a prefix, then you are telling it to set the namespace that is the value of the attribute as the default namespace for the page. If you omit in completely the default namespace is then assumed to be the value of the attribute (after the = and between the quotes).
XAML is XML and chooses to use the XML mechanism for declaring namespaces. I guess they could have created their own mechanism for doing it but since they didn't, if you added your namespace as you hint at in your question, without the xmlns:, the app processing the XML (the .NET framework in this case, parses the XAML file) would not know you were trying to define a namespace; it would think you were adding an attribute called "x" to the element it was defined in (which would most likely not be an attribute that is defined for that element).
For more about XML namespaces
http://www.w3.org/TR/REC-xml/
http://www.w3schools.com/XML/xml_namespaces.asp
http://en.wikipedia.org/wiki/XML_namespace
Related
If I have an attribute self.internal/freezer in a class, and I raise an error via (raise (AttributeError f"Sorry! '{attr}' doesn't exist as an attribute!")), how can I get the attribute name to render as internal/freezer instead of hyx_internalXsolidusXfreezer? For example, I already tried (hy.eval attr) with the f-string, but it still came out mangled.
Thanks to #Kodiologist in the comments linking the mangling section in hylang's syntax documentation; unamgling can be achieved via the aptly named hy.unmangle function, documented here as well.
I have 8 images and 2 canvas, and i am trying to do a drag drop game, which will be able to reject the wrong image that is drop into the wrong canvas. I tried many codes online just for the drag drop function but it didn't work. The most common error I have is
1) "The type 'WpfApplication9.Window1' already contains a definition for 'butterfly'"
2) 'WpfApplication9.Window1' does not contain a definition for 'Grid_PreviewMouseDown' and no extension method 'Grid_PreviewMouseDown' accepting a first argument of type 'WpfApplication9.Window1' could be found (are you missing a using directive or an assembly reference?)
How do solve the problem? Thankyou in advance
These are very basic errors and developers typically solve these by pasting them into any search engine and reading the result pages. If you can't fix these kinds of problems yourself, you'll have real problems later. Either way, your first error is this:
The type 'WpfApplication9.Window1' already contains a definition for 'butterfly'
In plain English, this means that you have a class named Window1 in a namespace named 'WpfApplication9 (so I'm assuming this is your 9th test application) and in that class, you have declared a property, method, enum, or other member named butterfly... the actual problem is that you have defined two members named butterfly in the same class. You cannot do this, so rename one of them.
Your second error is:
'WpfApplication9.Window1' does not contain a definition for 'Grid_PreviewMouseDown' and no extension method 'Grid_PreviewMouseDown' accepting a first argument of type 'WpfApplication9.Window1' could be found (are you missing a using directive or an assembly reference?)
Again, this is a very common error and simply means that you have attached a PreviewMouseDown event handler to your Grid, but then you didn't actually declare the handler method itself. The solution is to implement your Grid_PreviewMouseDown method.
this might be a very very basic question, but what is the best way to name my forms?
I mean, can I use spaces or will that give me problems later on?
Example
Should I use "Logged on Popup" or "Logged_on_Popup"?
Thanks!
Don't use spaces. Or Underscores. Microsoft do have some naming conventions that they recommend. Whilst they don't specifically have any recommendations re: form naming, they may be quite a good read:
Do favor readability over brevity. The property name CanScrollHorizontally is better than ScrollableX (an obscure reference to the X-axis).
Do not use underscores, hyphens, or any other nonalphanumeric characters.
Also, bear in mind that the name used in your code isn't exposed to the end users - whereas the captions of your forms are - make sure that those captions are well chosen.
Since Forms are also classes, you should follow the Class Namings:
Use a noun or noun phrase to name a class.
Use Pascal case.
Use abbreviations sparingly.
Do not use a type prefix, such as C for class, on a class name. For example, use the class name FileStream rather than CFileStream.
Do not use the underscore character (_).
Occasionally, it is necessary to provide a class name that begins with the letter I, even though the class is not an interface. This is appropriate as long as I is the first letter of an entire word that is a part of the class name. For example, the class name IdentityStore is appropriate.
Where appropriate, use a compound word to name a derived class. The second part of the derived class's name should be the name of the base class. For example, ApplicationException is an appropriate name for a class derived from a class named Exception, because ApplicationException is a kind of Exception. Use reasonable judgment in applying this rule. For example, Button is an appropriate name for a class derived from Control. Although a button is a kind of control, making Control a part of the class name would lengthen the name unnecessarily.
So Log On Popup is invalid and Log_On_Popup should be valid from a compiler perspective, but not from the class naming guidelines. I should opt for LogOnPopup. Where some people like to add a suffix to it LogOnPopupForm.
public partial class LoggedOnPopupForm
In component name you can use spaces but I don't recommend doing it
Simple,
You can use log_on_popup
If your doubt is how to name it then, When your Form designer is open, open the properties window (If properties window is not there, just right click on the form and select properties), In properties , You will find (Name) just type there log_on_popup :)
in a XAML file (a WPF UserControl), is there a way to reference an inner class "B" defined in another class "A" ?
public class A
{
public class B
{
}
}
Something like :
<local:A.B ... />
This syntax does not work because "B" is interpreted as a property named "B" in class "A".
I've tried more exotic syntaxes like "::" or "+" but none seems to work.
I'm currently using Silverlight 4 with VS2010.
Thanks in advance for your help.
This question is pretty old, and I don't know if it would have worked with the version of WPF back in 2010, but now you can make it work by using the "real" (internal) name of the nested type:
<local:A+B />
If you've ever looked a disassembled code, that's how nested types look like:
ParentTypeName+Nested
I was searching and searching, because if this is possible, I would like to know. Unfortunately, I found this on msdn:
Your custom class must not be a nested
class. Nested classes and the "dot"
in their general CLR usage syntax interfere with other WPF and/or XAML
features such as attached properties.
So, it appears you can't reference a nested class with the dot operator. As for alternative ways of getting to that inner class through XAML, I haven't had any luck in my searches yet. :o( But this is a rather interesting issue, so I will continue searching. Maybe I'll find some luck! :o)
. refers to a property; not sure why XAML couldn't also search for a nested class, but it doesn't.
A nested class can be represented when inside a string (e.g. a property value), using A+B instead of A.B:
<Label SomeProperty1="{x:Static local:A+B.SomeProperty2}" />
As an element name (as shown in question), + is not allowed, as the result would no longer be valid XML; + is not a valid name character:
XAML is XML.
XML Spec - NameChar.
So the element name cannot directly describe a nested class.
BUT see UPDATE below - an alternative syntax that solves this.
UPDATE
Per #Artfunkel's comment on one answer, this should be a solution [I have not tested]:
<x:Type TypeName="local:A+B"/>
From: https://learn.microsoft.com/en-us/dotnet/framework/xaml-services/x-type-markup-extension
TBD how to specify property name with that syntax. Use x:TypeArguments?
For example, the WPF namespace is:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
If I define my own namespace, should it also start with http? Isn't http misleading?
Namespaces doesn't have any meaning in their value, except for that value to be unique to avoid nameclashing. This is why you see a lot of companies putting in the URL for their own website as the namespace. URLs serve the same purpose, to be unique. Over the years it's just become good practice to use an URL, because if everyone does that, no nameclashing should occur :)
The W3C Document defining XML Namespaces says (quoting) :
Definition: An XML namespace is
identified by a URI reference
[RFC3986]
And RFC 3986 says (quoting) :
1.1.1. Generic Syntax
Each URI begins with a scheme name,
as defined in Section 3.1, that
refers to a specification for
assigning identifiers within that
scheme.
So I guess using http:// is what's closest to the standard -- as HTTP is the most common scheme used on the net.
In addition, as there can be only one owner for a domain name, it allows each company to use it's URL in its namespaces.
Another common way instead of using a URL starting with http:// is to use a Uniform Resource Name whose format is defined by RFC2141.
Such namespace identifiers are e.g. used by ODF (OpenDocument Format):
urn:oasis:names:tc:opendocument:xmlns:office:1.0
urn:oasis:names:tc:opendocument:xmlns:style:1.0
urn:oasis:names:tc:opendocument:xmlns:text:1.0
From this article at W3Schools:
"The namespace URI is not used by the parser to look up information. The purpose is to give the namespace a unique name. However, often companies use the namespace as a pointer to a web page containing namespace information. Try to go to http://www.w3.org/TR/html4/."
It is a reliable way to create a readable globally unique identifier. It may or may not be to a valid URL with more information.