Article complet: [Silverlight] Comment faire un TextBlock multiligne ?

10/03/2009

Permalink 20:37:00, Catégories: C#, Récapitulatif .NET, Récapitulatif, Silverlight, 125 mots   French (FR) , nico-pyright(c)

[.NET] [Silverlight] Comment faire un TextBlock multiligne ?

Pour faire un TextBlock multiligne, on va devoir utiliser la collection Inlines du contrôle. On y ajoutera des sections discrètes de texte (Classe System.Windows.Documents.Run), ainsi que des sauts de lignes (Classe System.Windows.Documents.LineBreak).

Ainsi, on peut imaginer 2 méthodes d'extensions qui font ca :

[Suite:]

public static class TextBlockExtensionMethods
{
   
public static void Append(this TextBlock textBlock, string text)
    {
       
if (string.IsNullOrEmpty(text))
           
return;
       
Run r = new Run { Text = text };
        textBlock.Inlines.Add(r);
    }

   
public static void AppendLine(this TextBlock textBlock, string text)
    {
       
if (!string.IsNullOrEmpty(text))
        {
           
Run r = new Run {Text = text};
            textBlock.Inlines.Add(r);
        }
        textBlock.Inlines.Add(
new LineBreak());
    }
}

A utiliser ainsi :

 

abx.Append("1ère ligne ...");
abx.AppendLine(
" Toujours sur la même ligne !");
abx.AppendLine(
"2ieme ligne");

Social Bookmarking:

                                     

Commentaires, Pingbacks:

Connectez-vous pour vous abonner à cet article:

Flux de commentaires pour cet article : Atom 1.0  RSS 2.0
Commentaire de: Philippe Vialatte [Membre]
je peux faire ma remarque a 2 cts ?

ça vaudrait pas le coup de faire :

public static void AppendLine(this TextBlock textBlock, string text)
{
textBlock.Append(text);
textBlock.Inlines.Add(new LineBreak());
}


Permalien 10/03/2009 @ 21:42
Commentaire de: nico-pyright(c) [Membre]
Sisi bien sur,
DRY !! :)
Sur le coup j'ai hésité ... et puis voila

Au fait, merci de m'avoir donné envie d'utiliser live writer, ca change la vie de bloggeur ;)
Permalien 10/03/2009 @ 21:51
Commentaire de: Philippe Vialatte [Membre]
> Au fait, merci de m'avoir donné envie d'utiliser live writer, ca change la vie de bloggeur ;)

We are the Borg. Resistance is futile. You will be assimilated. :D
Permalien 10/03/2009 @ 22:00

Vous devez être identifié pour poster un commentaire.

Liste des blogs

Blog de Nico-pyright(c)

Catégories


Rechercher

<  Janvier 2012  >
Lun Mar Mer Jeu Ven Sam Dim
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          

Syndiquez ce blog XML

Articles :

Commentaires :

 
 
 
 
Partenaires

Hébergement Web