using Windows.Foundation;
using Windows.Graphics.Display;
using Windows.UI;
using Windows.UI.Text;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Shapes;
namespace TestProject
{
/// <summary>
/// 메인 페이지
/// </summary>
public sealed partial class MainPage : Page
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 현재 색상
/// </summary>
private Color currentColor = Colors.Green;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainPage()
/// <summary>
/// 생성자
/// </summary>
public MainPage()
{
InitializeComponent();
#region 윈도우 크기를 설정한다.
double width = 800d;
double height = 600d;
double dpi = (double)DisplayInformation.GetForCurrentView().LogicalDpi;
ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;
Size windowSize = new Size(width * 96d / dpi, height * 96d / dpi);
ApplicationView.PreferredLaunchViewSize = windowSize;
Window.Current.Activate();
ApplicationView.GetForCurrentView().TryResizeView(windowSize);
#endregion
#region 윈도우 제목을 설정한다.
ApplicationView.GetForCurrentView().Title = "SplitButton 엘리먼트 : Style 속성에서 SplitButtonRevealStyle 리소스 사용하기";
#endregion
this.richEditBox.Document.Selection.CharacterFormat.ForegroundColor = this.currentColor;
this.richEditBox.Document.Selection.SetText
(
TextSetOptions.None,
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. " +
"Tempor commodo ullamcorper a lacus."
);
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
#region 분리 버튼 클릭시 처리하기 - splitButton_Click(sender, e)
/// <summary>
/// 분리 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void splitButton_Click(Microsoft.UI.Xaml.Controls.SplitButton sender, Microsoft.UI.Xaml.Controls.SplitButtonClickEventArgs e)
{
Rectangle rectangle = sender.Content as Rectangle;
Color color = (rectangle.Fill as SolidColorBrush).Color;
this.richEditBox.Document.Selection.CharacterFormat.ForegroundColor = color;
this.currentColor = color;
}
#endregion
#region 색상 버튼 클릭시 처리하기 - colorButton_Click(sender, e)
/// <summary>
/// 색상 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void colorButton_Click(object sender, RoutedEventArgs e)
{
Button colorButtonClicked = sender as Button;
Rectangle colorRectangleClicked = colorButtonClicked.Content as Rectangle;
Color colorClicked = (colorRectangleClicked.Fill as SolidColorBrush).Color;
this.richEditBox.Document.Selection.CharacterFormat.ForegroundColor = colorClicked;
this.currentColorRectangle.Fill = new SolidColorBrush(colorClicked);
this.splitButton.Flyout.Hide();
this.richEditBox.Focus(FocusState.Keyboard);
this.currentColor = colorClicked;
}
#endregion
#region 리치 에디트 박스 텍스트 변경시 처리하기 - richEditBox_TextChanged(sender, e)
/// <summary>
/// 리치 에디트 박스 텍스트 변경시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void richEditBox_TextChanged(object sender, RoutedEventArgs e)
{
if(this.richEditBox.Document.Selection.CharacterFormat.ForegroundColor != currentColor)
{
this.richEditBox.Document.Selection.CharacterFormat.ForegroundColor = currentColor;
}
}
#endregion
}
}