none
wpf affichage du texte dans un richtextbox RRS feed

  • Question

  • Bonjour,

    Il m'arrive quelque chose de curieux.

    J'ai un richtextbox dans mon application qui n'affiche qu'un seul caractère par ligne. Je n'arrive pas à voir pourquoi.

    Je vous remercie de m'éclairer.

    Cordialement

    <Grid Height="600">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="35"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions> 
                            <Grid.Resources> 
                                <Style TargetType="{x:Type Button}" x:Key="formatTextStyle">
                                    <Setter Property="FontFamily" Value="Palatino Linotype"/>
                                    <Setter Property="Width" Value="30"/>
                                    <Setter Property="FontSize" Value="14"/>
     
                              <Setter Property="CommandTarget" Value="{Binding ElementName=mainRTB}"/> 
                                </Style>
                                <Style TargetType="{x:Type Button}" x:Key="formatImageStyle">
                                    <Setter Property="Width" Value="30"/>  
                                    <Setter Property="BorderBrush" Value="Gray"/>
                                    <Setter Property="CommandTarget" Value="{Binding ElementName=mainRTB}"/>
                                </Style>
                            </Grid.Resources>
                            <DockPanel Name="mainPanel" Grid.Row="0">
                                <!-- ce toolbar conytient tous les boutons d'édition-->
                                <ToolBar Name="mainToolBar" DockPanel.Dock="Top" Height="40" Background="White">
                                    <Button x:Name="buttMainRTBOuvrir" Style="{StaticResource formatImageStyle}" Click="buttMainRTBOuvrir_Click" ToolTip="Onvrir" >
                                            <Image Source="C:\VendiStrat\VendittoreStratego\VendittoreStratego\VendittoreStratego\Images\EditTexte\2020FileOpen.png"></Image>
                                    </Button>
                                    <Button x:Name="buttMainRTBEnreg" Style="{StaticResource formatImageStyle}" Click="buttMainRTBEnreg_Click" ToolTip="Enregistrer">
                                           <Image Source="C:\VendiStrat\VendittoreStratego\VendittoreStratego\VendittoreStratego\Images\EditTexte\2020FileSave.png"/>
                                    </Button>
                                    <Button x:Name="buttMainRTBImprim" Style="{StaticResource formatImageStyle}" Click="buttMainRTBimprim_Click" ToolTip="Imprimer">
                                        <Image Source="C:\VendiStrat\VendittoreStratego\VendittoreStratego\VendittoreStratego\Images\EditTexte\2020Imprimante.png"/>
                                    </Button>
                                    <Separator />
                                    <Button Style="{StaticResource formatImageStyle}" Command="ApplicationCommands.Cut" ToolTip="Couper">
                                        <Image Source="C:\VendiStrat\VendittoreStratego\VendittoreStratego\VendittoreStratego\Images\EditTexte\2020CCPCut.png"/>
                                    </Button>
                                    <Button Style="{StaticResource formatImageStyle}" Command="ApplicationCommands.Copy" ToolTip="Copier">
                                        <Image Source="C:\VendiStrat\VendittoreStratego\VendittoreStratego\VendittoreStratego\Images\EditTexte\2020CCPCopy.png"/>
                                    </Button>
                                     <Button Style="{StaticResource formatImageStyle}" Command="ApplicationCommands.Paste" ToolTip="Coller">
                                            <Image Source="C:\VendiStrat\VendittoreStratego\VendittoreStratego\VendittoreStratego\Images\EditTexte\2020CCPPaste.png"/>
                                    </Button>
                                    <Button Style="{StaticResource formatImageStyle}" Command="ApplicationCommands.Undo" ToolTip="Annuler">
                                        <Image Source="C:\VendiStrat\VendittoreStratego\VendittoreStratego\VendittoreStratego\Images\EditTexte\2020CorrectUndo.png"/>
                                    </Button>
                                    <Button Style="{StaticResource formatImageStyle}" Command="ApplicationCommands.Redo" ToolTip="Refaire">
                                        <Image Source="C:\VendiStrat\VendittoreStratego\VendittoreStratego\VendittoreStratego\Images\EditTexte\2020CorrectRedo.png"/>
                                    </Button>
                                    <Button Style="{StaticResource formatImageStyle}" Command="EditingCommands.ToggleBold" ToolTip="Gras">
                                        <Image Source="C:\VendiStrat\VendittoreStratego\VendittoreStratego\VendittoreStratego\Images\EditTexte\2020FontBold.png"/>
                                    </Button>
                                    <Button Style="{StaticResource formatImageStyle}" Command="EditingCommands.ToggleItalic" ToolTip="Italique">
                                        <Image Source="C:\VendiStrat\VendittoreStratego\VendittoreStratego\VendittoreStratego\Images\EditTexte\2020FontItalic.png"/>
                                    </Button>
                                    <Button Style="{StaticResource formatImageStyle}" Command="EditingCommands.ToggleUnderline" ToolTip="Souligné">
                                        <Image Source="C:\VendiStrat\VendittoreStratego\VendittoreStratego\VendittoreStratego\Images\EditTexte\2020FontUnderline.png"/>
                                    </Button>
                                    <Button Style="{StaticResource formatImageStyle}" Command="EditingCommands.IncreaseFontSize" ToolTip="Agrandir">
                                        <Image Source="C:\VendiStrat\VendittoreStratego\VendittoreStratego\VendittoreStratego\Images\EditTexte\2020FontGrowfont.png"/>
                                    </Button>
                                    <Button Style="{StaticResource formatImageStyle}" Command="EditingCommands.DecreaseFontSize" ToolTip="Retrécir">
                                        <Image Source="C:\VendiStrat\VendittoreStratego\VendittoreStratego\VendittoreStratego\Images\EditTexte\2020FontShrinkfont.png"/>
                                    </Button> 
                                    <Button Style="{StaticResource formatImageStyle}" Command="EditingCommands.ToggleBullets" ToolTip="Puces">
                                        <Image Source="C:\VendiStrat\VendittoreStratego\VendittoreStratego\VendittoreStratego\Images\EditTexte\2020NumBullets.png"/>
                                    </Button>
                                    <Button Style="{StaticResource formatImageStyle}" Command="EditingCommands.ToggleNumbering" ToolTip="Numérotation">
                                        <Image Source="C:\VendiStrat\VendittoreStratego\VendittoreStratego\VendittoreStratego\Images\EditTexte\2020NumNum.png"/>
                                    </Button>
                                    <Separator/>
                                    <Button Style="{StaticResource formatImageStyle}" Command="EditingCommands.AlignLeft" ToolTip="Aligner à gauche">
                                        <Image Source="C:\VendiStrat\VendittoreStratego\VendittoreStratego\VendittoreStratego\Images\EditTexte\2020JustifyLeft.png"/>
                                    </Button>                     
                                    <Button Style="{StaticResource formatImageStyle}" Command="EditingCommands.AlignCenter" ToolTip="Aligner au centre">
                                        <Image Source="C:\VendiStrat\VendittoreStratego\VendittoreStratego\VendittoreStratego\Images\EditTexte\2020JustifyCenter.png"/>
                                    </Button>                                   
                                    <Button Style="{StaticResource formatImageStyle}" Command="EditingCommands.AlignRight" ToolTip="Aligner à droite">
                                        <Image Source="C:\VendiStrat\VendittoreStratego\VendittoreStratego\VendittoreStratego\Images\EditTexte\2020JustifyRight.png"/>
                                    </Button>                                
                                     <Button Style="{StaticResource formatImageStyle}" Command="EditingCommands.AlignJustify" ToolTip="Justifier">
                                        <Image Source="C:\VendiStrat\VendittoreStratego\VendittoreStratego\VendittoreStratego\Images\EditTexte\2020JustifyFully.png"/>
                                    </Button>
                                    <Separator/>
                                    <Button Style="{StaticResource formatImageStyle}" Command="EditingCommands.IncreaseIndentation" ToolTip="Augmenter l'indentation">
                                        <Image Source="C:\VendiStrat\VendittoreStratego\VendittoreStratego\VendittoreStratego\Images\EditTexte\2020IndentationIncrease.png"/>
                                    </Button>
                                     <Button Style="{StaticResource formatImageStyle}" Command="EditingCommands.DecreaseIndentation" ToolTip="Diminuer l'indentation">
                                        <Image Source="C:\VendiStrat\VendittoreStratego\VendittoreStratego\VendittoreStratego\Images\EditTexte\2020IndentationDecrease.png"/>
                                    </Button>    
                                    
                                    <Separator />
                                     
                                    <ComboBox Name="cmbFontFamily" Width="150" SelectionChanged="cmbFontFamily_SelectionChanged" BorderBrush="Gray" ToolTip="Police"/>
                               
                                    <ComboBox Name="cmbFontSize" Width="50"  SelectionChanged="cmbFontSize_SelectionChanged" BorderBrush="Gray" Margin="2" ToolTip="Taille"/>
    
                                </ToolBar>
                            </DockPanel>
                            <RichTextBox Name="mainRTB"  Margin="10" Grid.Row="1" Width="auto">
                                
                            </RichTextBox>
                        </Grid>
    
    
                    </TabItem>
                    <TabItem Name="tITel" Header="Téléphone" Style="{StaticResource TabItemApp}"  Width="Auto" Height="22">
                        <DataGrid x:Name="dtgTelephone">
    
                        </DataGrid>
                    </TabItem>
    
                    <TabItem  Name="tIMail" Header="Mail" Style="{StaticResource TabItemApp}"  Width="Auto" Height="22">
                        <DataGrid x:Name="dtgMail">
    
                        </DataGrid>
                    </TabItem>
                    <TabItem Name="tICourrier"  Header="Courrier" Style="{StaticResource TabItemApp}"  Width="Auto" Height="22">
                        <DataGrid x:Name="dtgCourrier">
    
                        </DataGrid>
                    </TabItem>
                    <TabItem Name="tIProposition" Header="Propositions" Style="{StaticResource TabItemApp}"  Width="Auto" Height="22">
    
                    </TabItem>
                    <TabItem Name="tICR" Header="Compte-rendu" Style="{StaticResource TabItemApp}"  Width="Auto" Height="22">
                        <DataGrid x:Name="dtgCRs">
    
                        </DataGrid>
                    </TabItem>
                    <TabItem Name="tIAction" Header="Action" Style="{StaticResource TabItemApp}"  Width="Auto" Height="22">
                        <DataGrid x:Name="dtgActions">
    
                        </DataGrid>
                    </TabItem>
                    <TabItem Name="tIDemande" Header="Demandes" Style="{StaticResource TabItemApp}"  Width="Auto" Height="22">
                        <DataGrid x:Name="dtgDemandes">
    
                        </DataGrid>
                    </TabItem>
                    <TabItem Name="tIRV" Header="Rendez-vous" Style="{StaticResource TabItemApp}"  Width="Auto" Height="22">
                        <DataGrid x:Name="dtgRV">
    
                        </DataGrid>
                    </TabItem>
                </TabControl>
            </GroupBox>
            <GroupBox Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="4" Header="Messages">
    
            </GroupBox>
        </Grid>

      
    lundi 4 mai 2020 15:45

Toutes les réponses

  • Bonjour,

    Pour afficher un texte dans un RichTextBox, essayez de la manière suivante:

    <RichTextBox Name="mainRTB">
          <FlowDocument>
            <Paragraph>
              Texte à afficher
            </Paragraph>
          </FlowDocument>
    </RichTextBox>


    Cordialement,
    Nina

    Microsoft propose ce service gratuitement, dans le but d'aider les utilisateurs et d'élargir les connaissances générales liées aux produits et technologies Microsoft. Ce contenu est fourni "tel quel" et il n'implique aucune responsabilité de la part de Microsoft.

    mardi 5 mai 2020 13:49
    Modérateur
  • Merci pour votre aide mais..

    Cela ne fonctionne pas. Le resultat est le même.

    mardi 5 mai 2020 14:15
  • Le code XAML posté n'est pas compilable après le premier  </Grid>

    Il commence par un </TabItem>

    Il manque le TabControl, GroupBox, ...

    dimanche 10 mai 2020 13:08