Skip to content

Commit

Permalink
Example code for NumberBox
Browse files Browse the repository at this point in the history
  • Loading branch information
NotYoojun committed Nov 29, 2024
1 parent 277afe1 commit 6b4582b
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 28 deletions.
70 changes: 43 additions & 27 deletions source/iNKORE.UI.WPF.Modern.Gallery/ControlPages/NumberBoxPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
xmlns:ikw="http://schemas.inkore.net/lib/ui/wpf"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
mc:Ignorable="d">
mc:Ignorable="d" Loaded="Page_Loaded">
<ikw:SimpleStackPanel>
<local:ControlExample HeaderText="A NumberBox that evaluates expressions.">
<local:ControlExample x:Name="Example1" HeaderText="A NumberBox that evaluates expressions.">
<ui:NumberBox
AcceptsExpression="True"
Header="Enter an expression:"
PlaceholderText="1 + 2^2"
Value="NaN" />
</local:ControlExample>

<local:ControlExample HeaderText="A NumberBox with a spin button.">
<local:ControlExample x:Name="Example2" HeaderText="A NumberBox with a spin button.">
<ui:NumberBox
x:Name="NumberBoxSpinButtonPlacementExample"
Header="Enter an integer:"
Expand All @@ -28,23 +28,25 @@

<local:ControlExample.Options>
<ikw:SimpleStackPanel Style="{StaticResource OptionsPanelStyle}">
<ui:RadioButtons Header="SpinButton Placement" SelectedItem="{Binding ElementName=NumberBoxSpinButtonPlacementExample, Path=SpinButtonPlacementMode}">
<ui:RadioButtons Header="SpinButton Placement"
SelectedItem="{Binding ElementName=NumberBoxSpinButtonPlacementExample, Path=SpinButtonPlacementMode}"
SelectionChanged="RadioButtons_SelectionChanged">
<ui:NumberBoxSpinButtonPlacementMode>Inline</ui:NumberBoxSpinButtonPlacementMode>
<ui:NumberBoxSpinButtonPlacementMode>Compact</ui:NumberBoxSpinButtonPlacementMode>
</ui:RadioButtons>
</ikw:SimpleStackPanel>
</local:ControlExample.Options>
</local:ControlExample>

<local:ControlExample HeaderText="A formatted NumberBox that rounds to the nearest 0.25.">
<local:ControlExample x:Name="Example3" HeaderText="A formatted NumberBox that rounds to the nearest 0.25.">
<ui:NumberBox
x:Name="FormattedNumberBox"
Header="Enter a dollar amount:"
PlaceholderText="0.00"
Value="NaN" />
</local:ControlExample>

<local:ControlExample HeaderText="API in action">
<local:ControlExample x:Name="Example4" HeaderText="API in action">
<ui:NumberBox
x:Name="NumberBox1"
Width="200"
Expand All @@ -56,41 +58,55 @@

<local:ControlExample.Options>
<ikw:SimpleStackPanel Style="{StaticResource OptionsPanelStyle}">
<ui:NumberBox Header="Minimum" Value="{Binding ElementName=NumberBox1, Path=Minimum}" />
<ui:NumberBox Header="Maximum" Value="{Binding ElementName=NumberBox1, Path=Maximum}" />
<ui:NumberBox
Header="SmallChange"
<ui:NumberBox Header="Minimum" Value="{Binding ElementName=NumberBox1, Path=Minimum}"
ValueChanged="NumberBox_ValueChanged"/>
<ui:NumberBox Header="Maximum" Value="{Binding ElementName=NumberBox1, Path=Maximum}"
ValueChanged="NumberBox_ValueChanged"/>
<ui:NumberBox Header="SmallChange"
SpinButtonPlacementMode="Inline"
Value="{Binding ElementName=NumberBox1, Path=SmallChange}" />
<ui:NumberBox
Header="LargeChange"
Value="{Binding ElementName=NumberBox1, Path=SmallChange}"
ValueChanged="NumberBox_ValueChanged"/>
<ui:NumberBox Header="LargeChange"
SpinButtonPlacementMode="Inline"
Value="{Binding ElementName=NumberBox1, Path=LargeChange}" />
Value="{Binding ElementName=NumberBox1, Path=LargeChange}"
ValueChanged="NumberBox_ValueChanged"/>
<TextBox
ui:ControlHelper.Header="Text"
IsEnabled="False"
Text="{Binding ElementName=NumberBox1, Path=Text, Mode=OneWay}" />
<TextBox ui:ControlHelper.Header="Header" Text="{Binding ElementName=NumberBox1, Path=Header, UpdateSourceTrigger=PropertyChanged}" />
<TextBox ui:ControlHelper.Header="PlaceholderText" Text="{Binding ElementName=NumberBox1, Path=PlaceholderText, UpdateSourceTrigger=PropertyChanged}" />
<TextBox ui:ControlHelper.Header="Description" Text="{Binding ElementName=NumberBox1, Path=Description, UpdateSourceTrigger=PropertyChanged}" />
Text="{Binding ElementName=NumberBox1, Path=Text, Mode=OneWay}"
TextChanged="TextBox_TextChanged"/>
<TextBox ui:ControlHelper.Header="Header"
Text="{Binding ElementName=NumberBox1, Path=Header, UpdateSourceTrigger=PropertyChanged}"
TextChanged="TextBox_TextChanged"/>
<TextBox ui:ControlHelper.Header="PlaceholderText"
Text="{Binding ElementName=NumberBox1, Path=PlaceholderText, UpdateSourceTrigger=PropertyChanged}"
TextChanged="TextBox_TextChanged"/>
<TextBox ui:ControlHelper.Header="Description"
Text="{Binding ElementName=NumberBox1, Path=Description, UpdateSourceTrigger=PropertyChanged}"
TextChanged="TextBox_TextChanged"/>
<ComboBox
ui:ControlHelper.Header="ValidationMode"
ItemsSource="{Binding Source={x:Type ui:NumberBoxValidationMode}, Converter={StaticResource EnumValuesConverter}}"
SelectedItem="{Binding ElementName=NumberBox1, Path=ValidationMode}" />
SelectedItem="{Binding ElementName=NumberBox1, Path=ValidationMode}"
SelectionChanged="ComboBox_SelectionChanged"/>
<ComboBox
ui:ControlHelper.Header="SpinButtonPlacementMode"
ItemsSource="{Binding Source={x:Type ui:NumberBoxSpinButtonPlacementMode}, Converter={StaticResource EnumValuesConverter}}"
SelectedItem="{Binding ElementName=NumberBox1, Path=SpinButtonPlacementMode}" />
<CheckBox Content="IsWrapEnabled" IsChecked="{Binding ElementName=NumberBox1, Path=IsWrapEnabled}" />
<CheckBox Content="AcceptsExpression" IsChecked="{Binding ElementName=NumberBox1, Path=AcceptsExpression}" />
<Slider
x:Name="CornerRadiusSlider"
SelectedItem="{Binding ElementName=NumberBox1, Path=SpinButtonPlacementMode}"
SelectionChanged="ComboBox_SelectionChanged"/>
<CheckBox Content="IsWrapEnabled"
IsChecked="{Binding ElementName=NumberBox1, Path=IsWrapEnabled}"
Click="CheckBox_Click"/>
<CheckBox Content="AcceptsExpression"
IsChecked="{Binding ElementName=NumberBox1, Path=AcceptsExpression}"
Click="CheckBox_Click"/>
<Slider x:Name="CornerRadiusSlider"
ui:ControlHelper.Header="CornerRadius"
AutoToolTipPlacement="TopLeft"
IsSnapToTickEnabled="True"
Maximum="20"
TickFrequency="1"
Value="{Binding ElementName=NumberBox1, Path=CornerRadius, Converter={StaticResource CornerRadiusToDoubleConverter}}" />
Maximum="20" TickFrequency="1"
Value="{Binding ElementName=NumberBox1, Path=CornerRadius, Converter={StaticResource CornerRadiusToDoubleConverter}}"
ValueChanged="CornerRadiusSlider_ValueChanged"/>
<ui:NumberBox
Header="PopupHorizonalOffset"
SpinButtonPlacementMode="Inline"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,96 @@ public string FormatDouble(double value)
private void PopupHorizonalOffset_ValueChanged(NumberBox sender, NumberBoxValueChangedEventArgs args)
{
NumberBox1.Resources["NumberBoxPopupHorizonalOffset"] = args.NewValue;
UpdateExampleCode();
}

private void PopupVerticalOffset_ValueChanged(NumberBox sender, NumberBoxValueChangedEventArgs args)
{
NumberBox1.Resources["NumberBoxPopupVerticalOffset"] = args.NewValue;
UpdateExampleCode();
}

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

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

private void NumberBox_ValueChanged(NumberBox sender, NumberBoxValueChangedEventArgs args)
{
UpdateExampleCode();
}

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

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

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

private void CornerRadiusSlider_ValueChanged(object sender, System.Windows.RoutedPropertyChangedEventArgs<double> e)
{
UpdateExampleCode();
}


#region Example Code

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

Example1.Xaml = Example1Xaml;
Example2.Xaml = Example2Xaml;
Example3.Xaml = Example3Xaml;
Example4.Xaml = Example4Xaml;
}

#endregion
public string Example1Xaml => $@"
<ui:NumberBox AcceptsExpression=""True""
Header=""Enter an expression:""
PlaceholderText=""1 + 2^2"" Value=""NaN"" />
";

public string Example2Xaml => $@"
<ui:NumberBox x:Name=""NumberBoxSpinButtonPlacementExample""
Header=""Enter an integer:"" Value=""10""
SpinButtonPlacementMode=""{NumberBoxSpinButtonPlacementExample.SpinButtonPlacementMode}""
SmallChange=""10"" LargeChange=""100"" />
";

public string Example3Xaml => $@"
<ui:NumberBox x:Name=""FormattedNumberBox""
Header=""Enter a dollar amount:""
PlaceholderText=""0.00"" Value=""NaN"" />
";

public string Example4Xaml => $@"
<ui:NumberBox x:Name=""NumberBox1""
Header=""{NumberBox1.Header}""
Maximum=""{NumberBox1.Maximum}"" Minimum=""{NumberBox1.Minimum}""
PlaceholderText=""{NumberBox1.PlaceholderText}""
SpinButtonPlacementMode=""{NumberBox1.SpinButtonPlacementMode}""
Description=""{NumberBox1.Description}""
ValidationMode=""{NumberBox1.ValidationMode}""
IsWrapEnabled=""{NumberBox1.IsWrapEnabled}""
AcceptsExpression=""{NumberBox1.AcceptsExpression}""
CornerRadius=""{NumberBox1.CornerRadius}""
</ui:NumberBox>
";

#endregion
}
}

0 comments on commit 6b4582b

Please sign in to comment.