Skip to content

Commit

Permalink
Example code for TextBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
NotYoojun committed Jan 7, 2025
1 parent 4983fef commit ccf6add
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,69 +21,31 @@
<local:ControlExample.Example>
<TextBlock Text="I am a TextBlock." />
</local:ControlExample.Example>
<local:ControlExample.Xaml>
<sys:String>
&lt;TextBlock Text=&quot;I am a TextBlock&quot;/&gt;
</sys:String>
</local:ControlExample.Xaml>
</local:ControlExample>
<local:ControlExample x:Name="Example2" HeaderText="A TextBlock with a style applied.">
<local:ControlExample.Example>
<TextBlock Style="{StaticResource CustomTextBlockStyle}" Text="I am a styled TextBlock." />
</local:ControlExample.Example>
<local:ControlExample.Xaml>
<sys:String xml:space="preserve">
&lt;Page.Resources&gt;
&lt;Style TargetType=&quot;TextBlock&quot; x:Key=&quot;CustomTextBlockStyle&quot;&gt;
&lt;Setter Property=&quot;FontFamily&quot; Value=&quot;Comic Sans MS&quot;/&gt;
&lt;Setter Property=&quot;FontStyle&quot; Value=&quot;Italic&quot;/&gt;
&lt;/Style&gt;
&lt;Page.Resources&gt;

&lt;TextBlock Text=&quot;I am a styled TextBlock&quot; Style=&quot;{StaticResource CustomTextBlockStyle}&quot;/&gt;
</sys:String>
</local:ControlExample.Xaml>
</local:ControlExample>
<local:ControlExample x:Name="Example3" HeaderText="A TextBlock with various properties set.">
<local:ControlExample.Example>
<TextBlock
FontFamily="Arial"
FontSize="24"
FontStyle="Italic"
Foreground="CornflowerBlue"
Text="I am super excited to be here!"
TextWrapping="Wrap" />
<TextBlock Foreground="CornflowerBlue" TextWrapping="Wrap"
FontFamily="Arial" FontSize="24" FontStyle="Italic"
Text="I am super excited to be here!" />
</local:ControlExample.Example>
<local:ControlExample.Xaml>
<sys:String xml:space="preserve">
&lt;TextBlock Text=&quot;I am super excited to be here!&quot; FontFamily=&quot;Arial&quot;
FontSize=&quot;24&quot; FontStyle=&quot;Italic&quot; TextWrapping=&quot;WrapWholeWords&quot;
CharacterSpacing=&quot;200&quot; Foreground=&quot;CornflowerBlue&quot; /&gt;
</sys:String>
</local:ControlExample.Xaml>
</local:ControlExample>
<local:ControlExample x:Name="Example4" HeaderText="A TextBlock with inline text elements.">
<local:ControlExample.Example>
<TextBlock>
<Run FontFamily="Times New Roman" Foreground="DarkGray">Text in a TextBlock doesn't have to be a simple string.</Run>
<LineBreak />
<Span>
Text can be<Bold>bold</Bold>
,<Italic>italic</Italic>
, or<Underline>underlined</Underline>
.</Span></TextBlock>
Text can be<Bold>bold</Bold>,
<Italic>italic</Italic>,
or<Underline>underlined</Underline>.
</Span>
</TextBlock>
</local:ControlExample.Example>
<local:ControlExample.Xaml>
<sys:String xml:space="preserve">
&lt;TextBlock&gt;
&lt;Run FontFamily=&quot;Times New Roman&quot; Foreground=&quot;DarkGray&quot;&gt;
Text in a TextBlock doesn't have to be a simple string.&lt;/Run&gt;
&lt;LineBreak/&gt;
&lt;Span&gt;Text can be &lt;Bold&gt;bold&lt;/Bold&gt;,
&lt;Italic&gt;italic&lt;/Italic&gt;, or &lt;Underline&gt;underlined&lt;/Underline&gt;. &lt;/Span&gt;
&lt;/TextBlock&gt;
</sys:String>
</local:ControlExample.Xaml>
</local:ControlExample>
</StackPanel>
</ui:Page>
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,47 @@ public partial class TextBlockPage : Page
public TextBlockPage()
{
InitializeComponent();
UpdateExampleCode();
}

#region Example Code

public void UpdateExampleCode()
{
if (!this.IsInitialized) return;

Example1.Xaml = Example1Xaml;
Example2.Xaml = Example2Xaml;
Example3.Xaml = Example3Xaml;
Example4.Xaml = Example4Xaml;
}

public string Example1Xaml => $@"
<TextBlock Text=""I am a TextBlock."" />
";

public string Example2Xaml => $@"
<TextBlock Style=""{{StaticResource CustomTextBlockStyle}}"" Text=""I am a styled TextBlock."" />
";

public string Example3Xaml => $@"
<TextBlock Foreground=""CornflowerBlue"" TextWrapping=""Wrap""
FontFamily=""Arial"" FontSize=""24"" FontStyle=""Italic""
Text=""I am super excited to be here!"" />
";

public string Example4Xaml => $@"
<TextBlock>
<Run FontFamily=""Times New Roman"" Foreground=""DarkGray"">Text in a TextBlock doesn't have to be a simple string.</Run>
<LineBreak />
<Span>
Text can be<Bold>bold</Bold>,
<Italic>italic</Italic>,
or<Underline>underlined</Underline>.
</Span>
</TextBlock>
";

#endregion

}
Expand Down

0 comments on commit ccf6add

Please sign in to comment.