@ -24,6 +24,14 @@ namespace Microsoft.Windows.Controls
public void SetText ( System . Windows . Documents . FlowDocument document , string text )
public void SetText ( System . Windows . Documents . FlowDocument document , string text )
{
{
try
try
{
//if the text is null/empty clear the contents of the RTB. If you were to pass a null/empty string
//to the TextRange.Load method an exception would occur.
if ( String . IsNullOrEmpty ( text ) )
{
document . Blocks . Clear ( ) ;
}
else
{
{
TextRange tr = new TextRange ( document . ContentStart , document . ContentEnd ) ;
TextRange tr = new TextRange ( document . ContentStart , document . ContentEnd ) ;
using ( MemoryStream ms = new MemoryStream ( Encoding . ASCII . GetBytes ( text ) ) )
using ( MemoryStream ms = new MemoryStream ( Encoding . ASCII . GetBytes ( text ) ) )
@ -31,9 +39,10 @@ namespace Microsoft.Windows.Controls
tr . Load ( ms , DataFormats . Xaml ) ;
tr . Load ( ms , DataFormats . Xaml ) ;
}
}
}
}
}
catch
catch
{
{
throw new InvalidDataException ( "d ata provided is not in the correct Xaml format." ) ;
throw new InvalidDataException ( "D ata provided is not in the correct Xaml format." ) ;
}
}
}
}
}
}