Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Append text to static resource

If I have the label:

<Label Content="{StaticResource Foo}" />

Is there a way of appending the * in xaml?

I am looking for something like:

<Label Content="{StaticResource Foo, stringformat={0}*" />

I am placing the content of my controls from a resource dictionary because the application supports multiple languages. I was wondering if I could append the * in xaml so that I do not have to create an event and then append it when that event fires.

Edit:

In a resource dictionary I have:

 <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:system="clr-namespace:System;assembly=mscorlib"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                >

     <system:String x:Key="Foo">Name</system:String>

 </ResourceDictionary>

in my window I have: ( I merge the last dictionary)

  <Label Content="{StaticResource 'Foo'}" />

and that displays Name

I will like the label to display Name* not just Name

Maybe it will be possible to achieve that with a style.

like image 637
Tono Nam Avatar asked Apr 16 '12 20:04

Tono Nam


People also ask

How do I add a static source to VS code?

To create a static resource: From Setup, enter Static Resources in the Quick Find box, then select Static Resources. Click New.

What are static resources in Salesforce?

Static resources allow you to upload content that you can reference in a Visualforce page, including archives (such as . zip and . jar files), images, style sheets, JavaScript, and other files. Static resources can be used only within your Salesforce org, so you can't host content here for other apps or websites.


1 Answers

There are multiple ways to do it:

  1. With ContentStringFormat:

    <Label Content="{StaticResource Foo}" ContentStringFormat='{}{0}*'/>
    
  2. With Binding with StringFormat (it only work on string properies thats why you need to use a TextBlock as the Label's content)

    <Label>
       <TextBlock 
           Text="{Binding Source={StaticResource Foo}, StringFormat='{}{0}*'}"/>
    </Label>
    
  3. Or you can write a converter to append the *
like image 186
nemesv Avatar answered Sep 28 '22 09:09

nemesv