Skip to content

Commit

Permalink
Example code for ToggleSwitch
Browse files Browse the repository at this point in the history
  • Loading branch information
NotYoojun committed Jan 22, 2025
1 parent 33c12f5 commit 3856871
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,32 @@
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
mc:Ignorable="d">
<ikw:SimpleStackPanel>
<local:ControlExample HeaderText="A simple ToggleSwitch.">
<local:ControlExample x:Name="Example1" HeaderText="A simple ToggleSwitch.">
<ui:ToggleSwitch AutomationProperties.Name="simple ToggleSwitch" />
</local:ControlExample>

<local:ControlExample HeaderText="A ToggleSwitch with custom header and content.">
<local:ControlExample x:Name="Example2" HeaderText="A ToggleSwitch with custom header and content.">
<StackPanel VerticalAlignment="Top" Orientation="Horizontal">
<ui:ToggleSwitch
x:Name="toggleSwitch"
Header="Toggle work"
IsOn="True"
OffContent="Do work"
OnContent="Working" VerticalAlignment="Top" />
<ui:ToggleSwitch x:Name="toggleSwitch"
Header="Toggle work" IsOn="True"
OffContent="Do work" OnContent="Working" VerticalAlignment="Top" />
<ui:ProgressRing Width="64" Height="64" IsActive="{Binding IsOn, ElementName=toggleSwitch}" />
</StackPanel>

<local:ControlExample.Options>
<ikw:SimpleStackPanel Style="{StaticResource OptionsPanelStyle}">
<CheckBox Content="IsOn" IsChecked="{Binding ElementName=toggleSwitch, Path=IsOn}" />
<TextBox ui:ControlHelper.Header="Header" Text="{Binding ElementName=toggleSwitch, Path=Header, UpdateSourceTrigger=PropertyChanged}" />
<TextBox ui:ControlHelper.Header="OnContent" Text="{Binding ElementName=toggleSwitch, Path=OnContent, UpdateSourceTrigger=PropertyChanged}" />
<TextBox ui:ControlHelper.Header="OffContent" Text="{Binding ElementName=toggleSwitch, Path=OffContent, UpdateSourceTrigger=PropertyChanged}" />
<CheckBox Content="IsOn"
IsChecked="{Binding ElementName=toggleSwitch, Path=IsOn}"
Click="CheckBox_Click"/>
<TextBox ui:ControlHelper.Header="Header"
Text="{Binding ElementName=toggleSwitch, Path=Header, UpdateSourceTrigger=PropertyChanged}"
TextChanged="TextBox_TextChanged"/>
<TextBox ui:ControlHelper.Header="OnContent"
Text="{Binding ElementName=toggleSwitch, Path=OnContent, UpdateSourceTrigger=PropertyChanged}"
TextChanged="TextBox_TextChanged"/>
<TextBox ui:ControlHelper.Header="OffContent"
Text="{Binding ElementName=toggleSwitch, Path=OffContent, UpdateSourceTrigger=PropertyChanged}"
TextChanged="TextBox_TextChanged"/>
</ikw:SimpleStackPanel>
</local:ControlExample.Options>
</local:ControlExample>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,40 @@ public partial class ToggleSwitchPage
public ToggleSwitchPage()
{
InitializeComponent();
UpdateExampleCode();
}

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

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


#region Example Code

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

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

public string Example1Xaml => $@"
<ui:ToggleSwitch AutomationProperties.Name=""simple ToggleSwitch"" />
";

public string Example2Xaml => $@"
<ui:ToggleSwitch x:Name=""toggleSwitch""
Header=""{toggleSwitch.Header}"" IsOn=""{toggleSwitch.IsOn}""
OffContent=""{toggleSwitch.OffContent}"" OnContent=""{toggleSwitch.OnContent}""/>
";

#endregion

}
Expand Down

0 comments on commit 3856871

Please sign in to comment.