String Format in xaml - silverlight-4.0

I have read so many blogs and find out we cna use stringFormat property in xaml to format the binded value without using converter.
I want to use the same thing,but dont know how is it possible in my case.
Like my string is Abc$% now using string format i want the result only Abc.
How can I use stringFormat in xaml so i can Got my desired result.
Thanks
Hardik

You can't do that using stringFormat. The stringFormat only allows you to decorate strings not manipulate them.
stringFormat works exactly like String.Format(...);
If you'd like to manipulate text in XAML, then you can try to create an IValueConverter class that chops off the text.

Related

How to bind the x:Uid of a TextBlock in XAML?

I am making a menu that can display many languages so I want to set the Uid of these TextBlock on each item, how can I set the Uid of a TextBlock in XAML through data binding. Because when I set x:Uid="{Binding Label}", the IDE shows that is an error. Please help me, thank you!
The binding is used Text="{Binding Label}", when you want value to be fetched from viewmodel. Drawback you will have to handle according to language the conversion of text.
x:Uid is supposed to be specified inside Strings->en_US folder. You create a resource file by default Resources.resw file inside it you add Name lets say Sample.Text and its Value as Your Text.
Inside your XAMl you are supposed to use x:Uid="Sample".
Now as per your requirement when you add more language using multilingual toolkit it would handle conversion for required language and on uploading to store it would select the particular language from app package and hence user views the app in the particular language they have selected on their device.
If you want to use the translation from strings folders you can instead of binding to the x:Uid value, bind the Text variable to a text key and use a value converter and find the translated text in code behind.
So the Xaml will look something like:
<TextBlock Text="{Binding Label, Converter={StaticResource TranslatorConverter}}"/>
Then you need the value converter:
public class TranslatorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
var resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView();
return resourceLoader.GetString(((String)value)); ;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
The "Label" in your Resources.resw file shall then simply be without the ".text" part that you use when using the x:Uid binding.
However if the multilingual toolkit as suggested is easier or not I donĀ“t know. I have not used the multilingual toolikt.

How to parse Date to DateTime in the own datagrid in Xaml

I have a little problem. My codebehind is returning a correctly datetime but when I show it in my grid (using devexpress) it isn't showing the time, just date. My code is:
<dxg:GridColumn Header="{lex:Loc col_HoraEntrada}" FieldName="HORA_CUADRANTE_ENTRADA" AutoFilterCondition="Contains"
My dateTime format 2015-11-17 13:30:00.000
And I don't know how to fix it.
Thanks.
In most of the cases when one data type should be converter to another data type just for presentation - you should use ValueConverter.
Here is very easy example of ValueConverter: WPF Tutorial
Just notice that ValueConverter instance should be defined as Resource. That's it: you should define it as entity that has x:Key parameter somewhere and then use it in you Binding

XAML bind to Collection[index].ObjectProperty

I have an observable collection of objects in my VM. I want to bind to a property of a specific item in the list in a text block, something like this:
Binding="{MyVMCollection[0].Description}"
But this syntax does not work. Is it possible to do what I am after and if so, how?
Thanks!
You're missing the Binding keyword and I think you also need to use Path.
Binding="{Binding Path=MyVMCollection[0].Description}"
The type of the object needs to be a type where an array index would normally work for this to work. I'm not sure the exact constraints but use Type[] if in doubt.
eg. If it is some weird enumerable type like IOrderedEnumerable<T> (or some wierd LINQy type) then something like {Binding List[0]} won't work.

Changing DataTemplate with Property Binding in Silverlight

I'm trying to implement this using Eugene Akinshin's code from here: http://forums.silverlight.net/t/237947.aspx/1
It seems like a really nice way to bind to already-existing properties and means the configuration can all be defined in XAML.
However, I can't get it to work.
I'm defining the templates to use like this:
<Converters:TemplateSelectorConverter x:Key="templateConverter">
<Converters:TemplateSelectorCase TemplateReference="Minimised" Template="{StaticResource SmallOrders}"/>
<Converters:TemplateSelectorCase TemplateReference="Restored" Template="{StaticResource MediumOrders}"/>
<Converters:TemplateSelectorCase TemplateReference="Maximised" Template="{StaticResource LargeOrders}"/>
</Converters:TemplateSelectorConverter>
and then setting the item template of my ListBox like this:
ItemTemplate="{Binding CurrentState, Converter={StaticResource templateConverter}}"
CurrentState is a string of either 'Minimised', 'Maximised' or 'Restored' (I've edited the linked example to have a string as the key rather than an int) and is set to 'Minimised' by default, but all I get is a list of Cannot create [my object type] in my ListBox.
The templates definitely work as I can expose the View in the ViewModel and set the DataTemplate in code, and there are visual states that rely on the same CurrentState property which work, so I know the View can access the property correctly. Unfortunately, if I breakpoint the Convert() method in the converter, it never gets hit.
All suggestions greatly appreciated!
Not sure if you have figured this out or not but placement of the Converter definition in the Resource in relationship to the DataTemplate will be the difference between it working and not working.
The Converter needs to be placed prior to the Data Template.

Objective-C: Any way to embed text formatting like < li>< /li> or < b>< /b> into a string in a plist?

I am a new objective-c/iPhone developer and am wondering if there is any way to embed formatting tags into a string in plist?
I have a plist that is an array of dictionaries. Each dictionary contains a few string objects, some of which I would like to contain lists and paragraphs of information.
Is there any way to embed tags like < li>< /li> or < b>< /b> into an string that will be recognized? If there is a way to do this, any reference to which tags are accepted would be greatly appreciated.
I have tried embedding these into the string from the xcode plist editor, tried using PlistEdit Pro, and also tried editing the xml, but have not had any luck so far!
Thanks in advance for your help.
Yes; you need to use XML entities:
<li>, etc.
You should be able to add them in (raw) in Property List Editor, though (they should be saved out as their entities in the actual XML plist).
#Wevah is correct: you do this by using XML entities. However, if you're programmatically using the built-in plist stuff (writing a plist object to a file, NSPropertyListSerialization, etc), then it will do the xml entity conversion for you.