How to allocate string including comma to control.Name property in wpf - wpf

Image im=new Image();
string ii="123456789";
im.Name=ii;
It's ok
but
Image im=new Image();
string ii="123.456.789";
im.Name=ii;
It throw exception. Why is it denied to allocate comma "." to control Name property?

The code you wrote is probably not what you want. As MDoobie said, there are restrictions on what the value of Name can be. The Image class is inheriting the Name property from its immediate parent class, "System.Windows.FrameworkElement." Follow MDoobie's "msdn" link to see what the purpose of that Name attribute is. Near the end of the Remarks you will see a link that will lead you to the specific information about Name restrictions.

In WPF, Names have some restrictions (for instance it cannot contains dots).
"The string values used for Name have some restrictions, as imposed by the underlying x:Name Directive defined by the XAML specification. Most notably, a Name must start with a letter or the underscore character (_), and must contain only letters, digits, or underscores. " (from msdn)

Related

Winforms ObjectListView: inner OLVColumn instances Name property is empty string so I cannot show/hide columns by name

This question is an offshoot of: Localizing ObjectListView OLVColumn, impossible due to Empty Name property
For simplicity's sake, let's say my ObjectListView contains car information. User A wants to display only Make and Model columns. User B only wants to display Model and Year columns. These preferences would be saved to/loaded from an .ini file on the users' local machines.
I cannot loop through the columns of the ObjectListView and do if (col.Name == colNameFromIni) { col.Visible == true; } because the .Name property of every column is an empty string ("") and does not get serialized to the designer codebehind file. This never happens with any other Winforms control (Label, Button, etc.) They always get their .Name written to the designer codebehind.
In some sense, this is a flaw in Winforms itself, because OLVColumn inherits from System.Windows.Forms.ColumnHeader, and a traditional ListView has exactly the same problem. .Name is always an empty string for all columns.
I would like to patch our local build of ObjectListView.dll to force populate the .Name property, but I can't figure out how Winforms automagically knows the name of every control on the form. It somehow(?) knows the names of the OLVColumn objects since it can display them in the Edit Columns... dialog on the ObjectListView's context menu. I'm also a little fuzzy on where the best spot is to plug this in.
(Yes, per linked question at top I know that as a last resort, I can hardcode colXX.Name = "colXX"; for all columns in my source code, but future column additions are likely to get overlooked and a programmatic solution is much preferred.)
(See also: https://sourceforge.net/p/objectlistview/bugs/160/ : the ObjectListView author declared this a wont-fix so it is up to me (or us), I guess.)
As you point out, this is a bug which is not with the ObjectListView, but the underlying component. And a bug which is around since at least 2008! Therefore, I doubt it will ever be fixed by MS.
Actually, it is a problem with the Autogenerated code in the designer.
If you look at other components such as a button, then the autogenerated code adds a name such as this;
//
// button2
//
this.button2.Location = new System.Drawing.Point(458, 199);
this.button2.Name = "button2";
...
But for ColumnHeader (Listview) and OLVColumn (ObjectListView), then this is not done, so then you end up with this.
//
// olvColumn1
//
this.olvColumn1.AspectName = "Name";
this.olvColumn1.Text = "Name";
If you manually add the line
this.olvColumn1.Text = "olvColumn1";
Then the "problem" is solved.
Of course, you can't do this, because the designer will override the autogenerated code when you make any changes, and then you will lose these manually added lines. It is also not sustainable.
So I'm afraid you need to code around this with some kind of ugly solution. Some options are:
Use the Tag to store the name and compare against this.
Use the text instead of the name (not possible if you have multi
language support!)
Code the names column manually in the Constructor
Set the Text to be something like "ColName;ColText" and then in your
code separate these out.
I have done option 3 in the past, but only I was maintaining the code, so this was easy.
What you could do to ensure you don't have discrepancies is to add a check in your constructor to compare the actual number of columns with the number you expect (hard coded for), and throw an exception if they don't match. Also, not the best, but another way to highlight and reduce errors.
The workaround for this is to get the OLVColumns via reflection and set their column's Name property at runtime. Every OLVColumn is a form-level field, so just pick them out of the list returned by GetFields().
Dim allFieldInfos As FieldInfo() = GetType(FrmMain).GetFields(BindingFlags.NonPublic or BindingFlags.Instance)
For Each fi As FieldInfo In allFieldInfos
If fi.FieldType Is GetType(OLVColumn) Then
Dim instance As OLVColumn = fi.GetValue(Me)
For Each col As OLVColumn In fdlvMain.AllColumns
If ReferenceEquals(col, instance) Then
col.Name = fi.Name
End If
Next
End If
Next

Why special Characters is invalid button content?

What the problem with this << give the button name like this not accepted in xaml
< , > , & , "" and space Thank You
Try this:
<Button Content="<<"/>
To explain this behavior we need to know the following:
Button is one of content controls, which are simply controls that are
constrained to contain a single item. Content controls all derive from
System.Windows.Controls.ContentControl, which has a Content property
of type Object that contains the single item. Because a content
control’s single item can be any arbitrary object, the control can
contain a potentially large tree of objects. There just can be only
one direct child.
If you open an Error list window, you can see many errors there, not just that one in your picture.
For me, it's
White space is missing.
The value "<" is not valid in an attribute.
Expecting an XML tag name.
The token "" HorizontalAlignment="Left" (omitted for brevity) is unexpected.
2x The open angle bracket character '<' is not valid in an attribute. It should be written as &amplt;.
Now, you could guess why it's not a valid character, not to mention that a solution is also described there in the last error. The compiler is confused, it thinks that you are nesting in a new UI element.
As for the other question about not allowed characters in a name, it's obvious. They are not allowed to be used in names in C# or VB.NET either. If you try it in XAML, it will produce an error saying what's allowed. It's just a decision made by a team who designed this. There are languages where these characters can be used as identifiers for objects.
There's a more elaborative explanation in the following blog post.
Try « for << and » for >> this are called "ISO Latin-1 code" for more checkout this link:
http://www.utexas.edu/learn/html/spchar.html
I have just written an answer which is
I guess you should use < instead.
but actually I mean
I guess you should use < instead.
The characters < in my answer were escaped to <.
<Button><</Button>

Custom Time Formatting what does 0: do?

Custom Date and Time Format Strings on MSDN
Link above seems to use {0:MM/dd/yy H:mm:ss zzz} a lot.
I understand all the letters and formatting options but I can't seem to find what the preceding "0:" is for?
The {0} is a composite formatting placeholder, meaning the first item in the format value list. For details, see this MSDN article, in particular, the section called "Composite Formatting" near the bottom, or the larger article specifically about Composite Formatting. But, to summarize:
In .NET there are two kinds of string formatting you can do: ToString formatting and composite formatting. Both of them use the same custom format string syntax.
When you have a single object, like a DateTime variable, and you call DateTime.ToString() on that object, you can pass a formatting string and it will apply to that object, and format it according to your pattern. But if you have more than one object and you want to build a complex string that includes their values, you instead call String.Format. That function expects a "format string" that contains placeholders where the variable bits go, which look like {0:g} or {5:MM/dd/yy} or something. The remainder of the parameters to String.Format is a list of variables. The {0} placeholder is the first variable, {5} is the 6th, etc.

Cypher accessing space separated relationship property neo4j

I have a few million nodes large data set imported with https://github.com/jexp/batch-import .
Unfortunately, the script made relationship property names space separated as in "Some Property".
How do I ask for this property in Cypher?
As expected
r.Some Property
does not work, which is only fair.
I also tried:
r["Some Property"]
Is there a syntax for such naming?
Should I just redo the import with camel case property names or underscore separated ones?
You can return properties with spaces in the names by using backticks, `, to enclose the property name. Something like this should work in Cypher:
START r=rel(0) RETURN r.`Some Property`;
This goes for node properties as well.
you can use MATCH (r) WHERE r.type=~'Some Property.*' RETURN r;
I hope this will get you exact relation-type.
OR
MATCH (n)-[r]->() WHERE type(r)=~'S.*' It will give you all relationship started with S.

FrameworkElement.Name problem

I am attempting to set the Name property of a Page in the constructor:
public partial class PageListView : Page
{
public PageListView(string title)
{
InitializeComponent();
Name = title;
}
}
However, I often get the following error message.
'x' is not a valid value for property 'Name'.
Where x seems to be almost anything, drilling down into the exception details doesn't seem to provide any useful information (e.g. the InnerException is null.)
Does anyone know what is happening here?
The Name property generally follows the rules of C#/VB.NET identifiers (i.e. fields). Based on the documentation:
The string values used for Name have some restrictions, as imposed by
the underlying x:Name Directive defined by the XAML specification.
Most notably, a Name must start with a letter or the underscore character
(_), and must contain only letters, digits, or underscores.
Based on the parameter you are passing (i.e. title), it seems like you may violate that. But you'd have to give some specific examples to be sure.
Of course, moments after posting this I realised what's going on.
Because FrameworkElement.Name is used for creating object references, you have to ensure that the string contains only valid chars for an object instance variable name.
Use Title or another plain text property instead, unless you really want to set the x:Name property for referencing.

Resources