using Windows.Foundation;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using CommunityToolkit.WinUI.UI.Controls;
namespace TestProject;
/// <summary>
/// 메인 페이지
/// </summary>
public sealed partial class MainPage : Page
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 마크다운 컨텐트 1
/// </summary>
private string markdownContent1 = @"
# 제목
이것은 **Markdown** 문서입니다.
- 목록 항목 1
- 목록 항목 2
- 목록 항목 3
```csharp
// 코드 블록 예제
Console.WriteLine(""Hello, World!"");
```
";
/// <summary>
/// 마크다운 컨텐트 2
/// </summary>
private string markdownContent2 = @"
";
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainPage()
/// <summary>
/// 생성자
/// </summary>
public MainPage()
{
InitializeComponent();
this.markdownTextBlock.MarkdownRendered += markdownTextBlock_MarkdownRendered;
this.changeTextButton.Click += changeTextButton_Click;
this.markdownTextBlock.Text = markdownContent1;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
//////////////////////////////////////////////////////////////////////////////// Event
#region 마크다운 텍스트 블럭 마크다운 렌더링시 처리하기 - markdownTextBlock_MarkdownRendered(sender, e)
/// <summary>
/// 마크다운 텍스트 블럭 마크다운 렌더링시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void markdownTextBlock_MarkdownRendered(object sender, MarkdownRenderedEventArgs e)
{
SetMarkdownTextBlockSize();
}
#endregion
#region 텍스트 변경 버튼 클릭시 처리하기 - changeTextButton_Click(sender, e)
/// <summary>
/// 텍스트 변경 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void changeTextButton_Click(object sender, RoutedEventArgs e)
{
if(this.markdownTextBlock.Text == this.markdownContent1)
{
this.markdownTextBlock.Text = this.markdownContent2;
}
else
{
this.markdownTextBlock.Text = this.markdownContent1;
}
}
#endregion
//////////////////////////////////////////////////////////////////////////////// Function
#region 마크다운 텍스브 블럭 크기 설정하기 - SetMarkdownTextBlockSize()
/// <summary>
/// 마크다운 텍스브 블럭 크기 설정하기
/// </summary>
private void SetMarkdownTextBlockSize()
{
if(string.IsNullOrWhiteSpace(this.markdownTextBlock.Text))
{
this.markdownTextBlock.Width = 200;
this.markdownTextBlock.Height = 50;
}
else
{
this.markdownTextBlock.Width = double.NaN;
this.markdownTextBlock.Height = double.NaN;
this.markdownTextBlock.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
this.markdownTextBlock.Width = this.markdownTextBlock.DesiredSize.Width + 20;
this.markdownTextBlock.Height = this.markdownTextBlock.DesiredSize.Height;
}
}
#endregion
}