Ampersand in XAML - silverlight

When I set the Text property of RolesTextName from codebehind in a Silverlight5 app by doing:
RolesTextName.Text = "David & Goliath";
<TextBlock TextWrapping="Wrap">
<Span FontWeight="Bold">Roles:</Span>
<Span><Run x:Name="RolesTextName" /></Span>
</TextBlock>
Problem: I don't get the & symbol, just the actual text.

XAML is used to create an object graph that represents your user interface. When you modify the user interface by setting property values in code the XAML has already been processed and is no longer used. You should not do any XAML specific encoding when modifying the object graph from code. Encoding is only required in XAML because it is based on XML and you need a way to represents characters like &, < and > unambgiously.
So executing
RolesTextName.Text = "David & Goliath";
will set the text of the run to
David & Goliath
To achieve what you want simply execute this code insted:
RolesTextName.Text = "David & Goliath";

Hi im also quite new to XML, but I've had a similar problem in the past
This link gave me some insight, hope it can help you.
`<![CDATA[Wake & Bake]]>
http://www.w3schools.com/xmL/xml_cdata.asp

Related

Covert a String to an Object which has a variable name

I searched for two hours, here on Stackoverflow and on other forums. But i can't find a solution for my problem. I have to be able to change the properties of an object that has a name that I don't know. Now i try to explain better:
The user drag some files in a form, and i get in a array() all the paths of the dragged files. For each path in files() i add to a panel a usercontrol that is the interface of an uploader. (My application it's kind of an uploader). Good, imagine that the user dragged 4 files, i have 4 different usercontrols, named "Uploader1", "Uploader2", "Uploader3" and "Uploader4". I need to change the text of a label in the uploader1, but i can't write:
Uploader1.LabelExample.Text = "Example"
Becouse it doesn't exist! (Not yet!)
So i tryed this method.
Dim UploadCounter as Integer = 1
Dim CurrentUploader = CType(Panel.Controls("Uploader" & UploaderCounter.ToString), UploadBanner)
CurrentUploader.LabelExample.Text = "Example"
I write the same with DirectCast and TryCast, but nothing.
I try also:
For Each Uploader With{.Name = "Uploader1"} as UploaderControl in Panel.Controls
Uploader.LabelExample.Text = "Example"
Next
I searched everywhere for "convert string to an object in vb.net" but i can't find anything that work! They all return "System.NullReferenceException: 'Object reference not set to an instance of an object.'"
Sorry for my bad bad english, thanks for all that will help me! need really!

XAML How to get a project name

Im learning XAML with microsoft visual studio 2013 wpf application.
I want to make a textblock display my Project Name from a some kind of resource(?) - I want to make a template :) .
Thank you for help in advance :) .
string name = Assembly.GetEntryAssembly().GetName().Name;
or
string name = Assembly.GetExecutingAssembly().GetName().Name;
Alternatively, you can get the Assembly object from any known type in the assembly:
Assembly assy = typeof({class name here}).Assembly;
This also allows another option to get the the name only:
string name = typeof({class name here}).Assembly.GetName().Name;
Here's the link

Password Mode of TextBox in F#

I am developing an windows application in F#. In the application I have to show the TextBox mode in Password Format. What is the code for using the password mode of TextBox in F#?
I have applied the following code:
let txtpwd = new TextBox(Top = 70, Left = 120)
From the above code the textbox is displaying. No problem. I have applied following code for password mode:
txtpwd.PasswordChar
The above code is not working properly.
You should set desired properties upon initialization of your control, for example:
txtpwd.Text <- "" // Set to no text
txtpwd.PasswordChar <-'*' // The password character is an asterisk
txtpwd.MaxLength <- 14 // The control will allow no more than 14 characters
Better yet, set the properties in your call to the constructor. One of the cool things about F# is that you can set properties in the call that you wouldn't normally be able to set in the constructor. Like this:
let txtpwd = new TextBox(Top = 70, Left = 120, Text = "", PasswordChar = '*',MaxLength = 14, Multiline = true)
This is basically equivalent to what Gene posted but, as far as I know, it's a little more idiomatic in F#.
If you check this page under the topic "Assigning Values To Properties At Initialization" (sorry can't post a direct link) although the page is discussing F# code, it holds for other .Net code as well.

How to set displaymember in code-behind?

XAML
<ComboBox Height="23.338" x:Name="cboCustom" />
Code which runs when the combobox should be populate
cboCustom.Items.Clear()
For x As Integer = 0 To (_collection.count - 1)
cboCustom.Items.Add(_collection.node(x))
Next
The _collection.node() is class with several properties
And I would like to set the displayMembervalue of the WPF combobo to it's description property.
I've tried
cboCustom.DisplayMemberPath = "myitem.description"
and
cboCustom.DisplayMemberPath = "description"
With no luck.
cboCustom.SeletedItem.description (on select action) does however give me the expected value.
Just use "Description" on its own (assuming that's the name of the property you want to display). Also, make sure the casing is correct.

String.Format, Currency, Polish Złoty

I am developing an e-commerce administration panel in WPF. I would like to display currency values in PLN (Polish Złoty). Format {0:C} gives output in USD ($1.000). Is there a way to change this behaviour or do I have to write my custom format to accomplish this?
edit:
Why this is so if my windows culture info and location are both set to Polish/Poland?
Try to pass CultureInfo in your String Format.
string money = String.Format(CultureInfo.GetCultureInfo("pl"), "{0:C}", 30.7m);
Console.WriteLine(money);
EDIT: if you are in WPF then this should do the trick:
this.Language = XmlLanguage.GetLanguage("pl");
or
FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage("pl")));
You sholud add only xml:lang="pl-PL" in your <Window> tag in MainWindows.xaml. Simple as that!

Resources