Replace data everytime on button click of a paragraph in a FlowDocumentReader

109 Views Asked by At

Searched many places but didn't got the desired solution. XAML:

<FlowDocumentReader  x:Name="fdr">
<FlowDocument x:Name="fd">
  <Paragraph x:Name="ParaData" />
   </FlowDocument>
  </FlowDocumentReader>

In the code behind in C# Im asigning value to the paragraph on button click. See below code:

private void ShowName_Click(object sender, RoutedEventArgs e)
{
    ParaData.Inlines.Add(new Run(txtEmpname.Text.ToString()));
}

PROBLEM IS: Everytime I click this button, the value is concatenated with the previous value in the paragraph, but I want the value to be replaced by the new value everytime on click.

1

There are 1 best solutions below

0
Tk1993 On BEST ANSWER

There is no such control for replacing the previous value of a paragraph. So before adding new value we can clear the previous value by using below code:

    ParaData.Inlines.Add(new Run(old_txtEmpname.Text.ToString()));
    ParaData.Inlines.Clear();
    ParaData.Inlines.Add(new Run(new_txtEmpname.Text.ToString()));