Skip to content

Commit

Permalink
Example code for RichEditBox
Browse files Browse the repository at this point in the history
  • Loading branch information
NotYoojun committed Dec 22, 2024
1 parent 82f1a3b commit fb92db2
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,59 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ikw="http://schemas.inkore.net/lib/ui/wpf"
xmlns:sc="clr-namespace:SamplesCommon;assembly=SamplesCommon"
xmlns:local="clr-namespace:iNKORE.UI.WPF.Modern.Gallery"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
mc:Ignorable="d">
mc:Ignorable="d" Loaded="Page_Loaded">

<ScrollViewer>
<ikw:SimpleStackPanel Style="{StaticResource ControlPageContentPanelStyle}">
<sc:ControlExample HeaderText="A simple text editor using RichTextBox.">
<local:ControlExample x:Name="Example1" HeaderText="A simple text editor using RichTextBox.">
<RichTextBox
x:Name="richTextBox"
ui:ControlHelper.Header="Control header"
ui:ControlHelper.PlaceholderText="Placeholder text"
SpellCheck.IsEnabled="True" />
</sc:ControlExample>
</local:ControlExample>

<sc:ControlExample HeaderText="API in action.">
<local:ControlExample x:Name="Example2" HeaderText="API in action.">
<RichTextBox
x:Name="textBox"
Width="296"
Height="105"
ui:ControlHelper.Header="Control header" />
<sc:ControlExample.Options>
<local:ControlExample.Options>
<ikw:SimpleStackPanel Style="{StaticResource OptionsPanelStyle}">
<CheckBox Content="AcceptsReturn" IsChecked="{Binding ElementName=textBox, Path=AcceptsReturn}" />
<CheckBox Content="IsReadOnly" IsChecked="{Binding ElementName=textBox, Path=IsReadOnly}" />
<CheckBox Content="IsReadOnlyCaretVisible" IsChecked="{Binding ElementName=textBox, Path=IsReadOnlyCaretVisible}" />
<CheckBox Content="IsUndoEnabled" IsChecked="{Binding ElementName=textBox, Path=IsUndoEnabled}" />
<CheckBox Content="IsInactiveSelectionHighlightEnabled" IsChecked="{Binding ElementName=textBox, Path=IsInactiveSelectionHighlightEnabled}" />
<CheckBox Content="SpellCheck" IsChecked="{Binding ElementName=textBox, Path=(SpellCheck.IsEnabled)}" />
<TextBox ui:ControlHelper.Header="Header" Text="{Binding ElementName=textBox, Path=(ui:ControlHelper.Header), UpdateSourceTrigger=PropertyChanged}" />
<TextBox ui:ControlHelper.Header="PlaceholderText" Text="{Binding ElementName=textBox, Path=(ui:ControlHelper.PlaceholderText), UpdateSourceTrigger=PropertyChanged}" />
<CheckBox Content="AcceptsReturn" IsChecked="{Binding ElementName=textBox, Path=AcceptsReturn}" Click="CheckBox_Click"/>
<CheckBox Content="IsReadOnly" IsChecked="{Binding ElementName=textBox, Path=IsReadOnly}" Click="CheckBox_Click"/>
<CheckBox Content="IsReadOnlyCaretVisible" IsChecked="{Binding ElementName=textBox, Path=IsReadOnlyCaretVisible}" Click="CheckBox_Click"/>
<CheckBox Content="IsUndoEnabled" IsChecked="{Binding ElementName=textBox, Path=IsUndoEnabled}" Click="CheckBox_Click" />
<CheckBox Content="IsInactiveSelectionHighlightEnabled" IsChecked="{Binding ElementName=textBox, Path=IsInactiveSelectionHighlightEnabled}" Click="CheckBox_Click" />
<CheckBox Content="SpellCheck" IsChecked="{Binding ElementName=textBox, Path=(SpellCheck.IsEnabled)}" Click="CheckBox_Click" />
<TextBox ui:ControlHelper.Header="Header" Text="{Binding ElementName=textBox, Path=(ui:ControlHelper.Header), UpdateSourceTrigger=PropertyChanged}" TextChanged="TextBox_TextChanged" />
<TextBox ui:ControlHelper.Header="PlaceholderText" Text="{Binding ElementName=textBox, Path=(ui:ControlHelper.PlaceholderText), UpdateSourceTrigger=PropertyChanged}" TextChanged="TextBox_TextChanged" />
<ComboBox
ui:ControlHelper.Header="HorizontalScrollBarVisibility"
ItemsSource="{Binding Source={x:Type ScrollBarVisibility}, Converter={StaticResource EnumValuesConverter}}"
SelectedItem="{Binding ElementName=textBox, Path=HorizontalScrollBarVisibility}" />
SelectedItem="{Binding ElementName=textBox, Path=HorizontalScrollBarVisibility}"
SelectionChanged="ComboBox_SelectionChanged"/>
<ComboBox
ui:ControlHelper.Header="VerticalScrollBarVisibility"
ItemsSource="{Binding Source={x:Type ScrollBarVisibility}, Converter={StaticResource EnumValuesConverter}}"
SelectedItem="{Binding ElementName=textBox, Path=VerticalScrollBarVisibility}" />
SelectedItem="{Binding ElementName=textBox, Path=VerticalScrollBarVisibility}"
SelectionChanged="ComboBox_SelectionChanged"/>
<ComboBox
ui:ControlHelper.Header="SelectionOpacity"
IsEditable="True"
SelectedItem="{Binding ElementName=textBox, Path=SelectionOpacity}">
SelectedItem="{Binding ElementName=textBox, Path=SelectionOpacity}"
SelectionChanged="ComboBox_SelectionChanged">
<sys:Double>0</sys:Double>
<sys:Double>0.4</sys:Double>
<sys:Double>1</sys:Double>
</ComboBox>
</ikw:SimpleStackPanel>
</sc:ControlExample.Options>
</sc:ControlExample>
</local:ControlExample.Options>
</local:ControlExample>
</ikw:SimpleStackPanel>
</ScrollViewer>
</ui:Page>
Original file line number Diff line number Diff line change
@@ -1,22 +1,70 @@
using System.Windows.Controls;
using System.Windows;
using System.Windows.Controls;
using iNKORE.UI.WPF.Modern.Controls.Helpers;
using iNKORE.UI.WPF.Modern.Controls;
using Page = iNKORE.UI.WPF.Modern.Controls.Page;


namespace iNKORE.UI.WPF.Modern.Gallery.ControlPages
{
public partial class RichEditBoxPage
public partial class RichEditBoxPage : Page
{
public RichEditBoxPage()
{
InitializeComponent();
}

private void Page_Loaded(object sender, RoutedEventArgs e)
{
UpdateExampleCode();
}

private void CheckBox_Click(object sender, RoutedEventArgs e)
{
UpdateExampleCode();
}

private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
UpdateExampleCode();
}

private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
UpdateExampleCode();
}


#region Example Code

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

Example1.Xaml = Example1Xaml;
Example2.Xaml = Example2Xaml;
}

#endregion
public string Example1Xaml => $@"
<RichTextBox x:Name=""richTextBox""
ui:ControlHelper.Header=""Control header""
ui:ControlHelper.PlaceholderText=""Placeholder text""
SpellCheck.IsEnabled=""True"" />
";

public string Example2Xaml => $@"
<RichTextBox x:Name=""textBox""
ui:ControlHelper.Header=""{ControlHelper.GetHeader(textBox)}""
ui:PlaceholderText=""{ControlHelper.GetPlaceholderText(textBox)}""
AcceptsReturn=""{textBox.AcceptsReturn}"" IsUndoEnabled=""{textBox.IsUndoEnabled}""
IsReadOnly=""{textBox.IsReadOnly}"" IsReadOnlyCaretVisible=""{textBox.IsReadOnlyCaretVisible}""
IsInactiveSelectionHighlightEnabled=""{textBox.IsInactiveSelectionHighlightEnabled}""
HorizontalScrollBarVisibility=""{textBox.HorizontalScrollBarVisibility}""
VerticalScrollBarVisibility=""{textBox.VerticalScrollBarVisibility}""
SelectionOpacity=""{textBox.SelectionOpacity}"" SpellCheck.IsEnabled=""{textBox.SpellCheck.IsEnabled}"" />
";


#endregion
}
}

0 comments on commit fb92db2

Please sign in to comment.