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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace WpfFlowDocumentScrollViewerTextesEtImages
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
InlineUIContainerExemple();
}
void InlineUIContainerExemple()
{
//*** construction des textes et images.
Run run1 = new Run(" Vous pouvez défausser une carte de votre Réserve. Si vous le faites : " +
"vous pouvez renvoyer un Personnage ou Permanent ciblé avec un Coût de Main ");
Run run2 = new Run(" ou moins dans la main");
Bold bold1 = new Bold(new Run(" de son propriétaire.", pgraph.ContentStart));
bold1.Foreground = Brushes.Maroon;
Image image1 = new Image();
image1.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Reserve.png"));
image1.Height = 18;
Image image2 = new Image();
image2.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Cinq1.png"));
image2.Height = 18;
//*** Création des InlineUIContainer pour contenir les images.
InlineUIContainer InlineUIContainer1 = new InlineUIContainer();
InlineUIContainer InlineUIContainer2 = new InlineUIContainer();
//*** Définir la propriété BaselineAlignment sur « Bottom » afin que les images
// s'alignent correctement avec le texte.
InlineUIContainer1.BaselineAlignment = BaselineAlignment.Bottom;
InlineUIContainer2.BaselineAlignment = BaselineAlignment.Bottom;
//*** Affecter l'image à son InlineUIContainer.
InlineUIContainer1.Child = image1;
InlineUIContainer2.Child = image2;
//*** Ajout du contenu au paragraphe, du paragraphe au flowdocument
// et du Flowdocument au FlowDocumentScrollViewer.
pgraph.Inlines.Add(InlineUIContainer1);
pgraph.Inlines.Add(run1);
pgraph.Inlines.Add(InlineUIContainer2);
pgraph.Inlines.Add(run2);
pgraph.Inlines.Add(bold1);
fdoc.Blocks.Add(pgraph);
fdocScrollViewer.Document = fdoc;
}
}
} |
Partager