Creating an instance of a nested class in XAML - wpf

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?

Related

How to Escape Property References in an OSGi Blueprint Properties file?

I'm trying to create a property in an OSGi properties file, where the property is a simple string, such as
fileName=${header.RecordType}.csv
However, this doesn't seem to work, and I assume that is because the ${...} is being processed as a property reference by the configuration manager, and since it doesn't exist as a property, is being blanked.
I've tried escaping the simple string reference as $${ and \${ but neither work.
Is it possible to somehow escape the ${ so that the property passed to the program is exactly as shown above?
Thanks for looking!
Use fileName=$simple{xxxx} as alternative syntax, which is also documented here:
https://camel.apache.org/manual/latest/simple-language.html

Dynamic in xaml Data Template selector

Ok I found this wonderful idea on code project.
link
The idea is great add all your data templates to collection in your list box. Tell each one what to look for (a type) and what data template to use when it runs into that type. The problem is that the included source code is different from the on page code and I can't seen to get any combination of it to work. Even adding the missing quotation marks and changing the type to a local class instead of the non-accessible string and int32 classes.
So the question is. What am I doing wrong?
Bryan
Should be totally redundant when you have DataTemplate.DataType.
(Example)

Visual Studio - naming forms

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 :)

"key cannot be null" when parsing xaml in a datagrid text column

I have a DataGrid and it has a text column in it, configured this way:
<dg:DataGridTextColumn Header="{x:Static ResViewModel:SC.Resources.HelloWorld}" />
Here ResViewModel is the xmlns:namespace, SC is the project namespace, Resources is the resource file name and HelloWorld is a string property.
But I try to parse this xaml, I get an error like
Key cannot be null. Parameter name: key...
Can you help me to understand why is this error occuring? Also what is the best way to access resource file without using the LocBAML tool?
I see some issues:
"SC is the project namespace" - that should go into the xmlns definition.
You can't access files with this syntax, unless you have a dependency object with the same name.
There's a good approach to retrieving strings that is described here. It's focusing on Localisation, but it will work for a single language as well. This approach has it's downsides, but it's the lesser evil than other routes.

pyamf exclude property not working on db.ReferenceProperty

I am using pyamf with google app engine. I am trying to exclude a property from the pyamf encoding. This is the syntax I am using:
class Comment(db.Model):
class __amf__:
exclude = ('article')
article = db.ReferenceProperty(Article)
comment = db.TextProperty()
This does not work on the ReferenceProperty but if I try the exclude property with the 'comment' attribute it works. I noticed that the exclude property worked on a ReferenceProperty that did not contain a class with another ReferenceProperty attribute. In this case the Article class holds another ReferenceProperty to a another class. Any idea what could be the problem?
Thanks in advance
Your problem seems to be, at least partly, one of syntax -- you want the following:
exclude = ('article',)
Single parentheses without commas in them are just parenthesized expressions; they are evaluated earlier but do not mean "this is a tuple literal" -- that requires a colon.

Resources