Skip to content

Commit

Permalink
Example code for ToggleButton
Browse files Browse the repository at this point in the history
  • Loading branch information
NotYoojun committed Jan 22, 2025
1 parent 7069fca commit ccdb39b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,13 @@
</local:ControlExample.Output>
<local:ControlExample.Options>
<StackPanel>
<CheckBox
<CheckBox x:Name="CheckBox_IsEnabled"
Content="Disable ToggleButton"
Loaded="CheckBox_Loaded"
Tag="DisableToggle1" />
Tag="DisableToggle1"
Click="CheckBox_IsEnabled_Click"/>
</StackPanel>
</local:ControlExample.Options>
<local:ControlExample.Xaml>
<sys:String>
&lt;ToggleButton Content=&quot;ToggleButton&quot; Click=&quot;Button_Click&quot; $(IsEnabled)/&gt;
</sys:String>
</local:ControlExample.Xaml>
</local:ControlExample>
</StackPanel>
</ui:Page>
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,15 @@ public partial class ToggleButtonPage : Page
public ToggleButtonPage()
{
InitializeComponent();
UpdateExampleCode();
}

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


private void ToggleButton_Checked(object sender, RoutedEventArgs e)
{
Control1Output.Text = "On";
Expand Down Expand Up @@ -112,10 +119,30 @@ private void CheckBox_Loaded(object sender, RoutedEventArgs e)

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

Example1.Xaml = Example1Xaml;
Example1.CSharp = Example1CS;
}

#endregion
public string Example1Xaml => $@"
<ToggleButton IsEnabled=""{CheckBox_IsEnabled.IsChecked}"" Content=""ToggleButton""
Checked=""ToggleButton_Checked""
Unchecked=""ToggleButton_Unchecked"" />
";

public string Example1CS => $@"
private void ToggleButton_Checked(object sender, RoutedEventArgs e)
{{
Control1Output.Text = ""On"";
}}
private void ToggleButton_Unchecked(object sender, RoutedEventArgs e)
{{
Control1Output.Text = ""Off"";
}}
";

#endregion
}
}

0 comments on commit ccdb39b

Please sign in to comment.