1

I've been needing to use a numeric up-down control for my WPF app. I read a similar question posted here and tried using the one available here > http://bot.codeplex.com/.

I added the references and referenced it in my XAML window

xmlns:lib="clr-namespace:PixelLab.Wpf;assembly=PixelLab.Wpf"

and did this.

<lib:NumericUpDown Name="year"></lib:NumericUpDown>

and keep getting the error: 'nud' is an undeclared namepsace.

I'm very new to WPF so any help would be appreciated.

4
  • If you get that error then somewhere in your code there's a 'nud' referenced. Find it and delete it or change it to 'lib'. Commented Sep 22, 2010 at 10:17
  • Searched the entire project for'nud' but did not find any matches. Commented Sep 22, 2010 at 10:38
  • 2
    Add the project(source code) into your application(instead of referencing it) and then try to debug the controls Initializer. You may get more specific error that way. Commented Sep 22, 2010 at 11:38
  • Create a new (temporary) WPF project, add the same reference to the PixelLab library, add the reference in XAML, and add a NumericUpDown to the Window. See if it runs. If it runs, it's a problem somewhere in your project. If you get the same error, it may be an error in the PixelLab library, so you should look at the source code for that. If you find an error in the library, report it to them, and follow up here for the benefit of anybody having the same issue. Commented Sep 22, 2010 at 12:58

3 Answers 3

3

Just combine a TextBox with a veritical fixed-height ScrollBar like this:

<Grid Height="80">
            <TextBox x:Name="part_TextBox" Text="{Binding Value,ElementName=part_Scrollbar,StringFormat={}{0:F6},Mode=TwoWay}" MaxLength="11" VerticalAlignment="Center" VerticalContentAlignment="Center" FontSize="24" Height="40"/>
            <ScrollBar x:Name="part_Scrollbar" Orientation="Vertical" Minimum="0" Maximum="100" BorderBrush="{x:Null}" SmallChange="0.1" Height="32" Margin="8 4" VerticalAlignment="Stretch" Grid.Column="1" RenderTransformOrigin="0.5,0.5" HorizontalAlignment="Right">
                <ScrollBar.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform/>
                        <SkewTransform/>
                        <RotateTransform Angle="180"/>
                        <TranslateTransform/>
                    </TransformGroup>
                </ScrollBar.RenderTransform>
            </ScrollBar>
        </Grid>

enter image description here

Bindings for Maximum & Minimum & SmallChange/Increment are directly avaliable.

Sign up to request clarification or add additional context in comments.

1 Comment

This is a very elegant solution, where do i find the different string formats?
2

The Extented WPF Toolkit has one: NumericUpDown enter image description here

Comments

1

Vanilla XAML (no additions or packages) implementation:

    <Window x:Class="Spinner.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Spinner"
        mc:Ignorable="d"
        ResizeMode="CanMinimize" SizeToContent="WidthAndHeight" Title="Scroll Spinner">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <!-- The button exists just to have something other than the spinner be the object of focus. -->
            <Button Content="Reset" TabIndex="0"/>
            <!-- The spinner is just a scroll bar overlaying a text box (same tab indices). -->
            <!-- Only the scroll bar is named (in order to get its value); the text box just relfects the scroll bar's value. -->
            <TextBox GotFocus="TextBox_GotFocus" Grid.Row="1" Height="{Binding ElementName=SpinnerScr, Path=ActualHeight}" HorizontalAlignment="Stretch" IsReadOnly="True" TabIndex="1" Text="{Binding ElementName=SpinnerScr, Path=Value, StringFormat={}{0:####0}}" TextAlignment="Center"/>
            <ScrollBar x:Name="SpinnerScr" Background="Transparent" Focusable="True" Grid.Row="1" Height="20" LostFocus="SpinnerScr_LostFocus" Margin="0,3" Maximum="999" Orientation="Horizontal" SmallChange="1" TabIndex="1" Visibility="Hidden"/>
            <x:Code>
                <![CDATA[
                void SpinnerScr_LostFocus(object sender, RoutedEventArgs e) {
                    SpinnerScr.Visibility = Visibility.Hidden;
                }
                void TextBox_GotFocus(object sender, RoutedEventArgs e) {
                    SpinnerScr.Visibility = Visibility.Visible;
                    SpinnerScr.Focus();
                }
            ]]>
            </x:Code>
        </Grid>
    </Window>

    using System.Windows;
    namespace Spinner {
        public partial class MainWindow : System.Windows.Window {
            public MainWindow() {
                InitializeComponent();
            }
        }
    }

enter image description here

When the scroll bar (or text box) has focus, the scroll elements are visible. On loss of focus, only the text box is visible. Only the scroll bar may be accessed in any code-behind.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.