views:

4982

answers:

3

Getting into the first serious WPF project. It seems like there are a lot of basic controls flat out missing. Specifically, I am looking for the Numeric UpDown control. Was there an out of band release that I missed? Really don't feel like writing my own control.

I do not want to use the WindowsFormHost and plop a WinForm ctl on it. I want it to be fully WPF without any legacy junk.

Thanks

+3  A: 

There isn't one built-in, but Kevin has one in his bag of tricks.

marklam
Thanks a lot. I saw this one as well. Kevin has a pretty amazing collection.
AngryHacker
+1  A: 

It does not exist, per se. You can find it as part of the SDKs samples.

Erich Mirabal
Erich, this is the one I found prior to asking the question. This is the WORST updown control I have ever seen. It consists of a textbox and 2 large buttons haphazardly dumped on the surface. The buttons don't even include arrows, just say UP and DOWN.
AngryHacker
it lacks some polish, yeah. But hey, you could have included that into your question: "a real NumUD control, and not the PoS from SDK Sample."
Erich Mirabal
Well, thanks for the effort. Upvoted.
AngryHacker
+3  A: 

I made my own;

the xaml

<StackPanel Orientation="Horizontal">
    <TextBox x:Name="txtNum" x:FieldModifier="private" Margin="5,5,0,5" Width="50" Text="0" TextChanged="txtNum_TextChanged" />
        <Button x:Name="cmdUp" x:FieldModifier="private" Margin="5,5,0,5" Content="˄" Width="20" Click="cmdUp_Click" />
        <Button x:Name="cmdDown" x:FieldModifier="private" Margin="0,5,0,5"  Content="˅" Width="20" Click="cmdDown_Click" />
    </StackPanel>

and the code behind

private int _numValue = 0;
    public int NumValue
    {
        get {  return _numValue; }
        set
        {
            _numValue = value;
            txtNum.Text = value.ToString();
        }
    }

    public NumberUpDown()
    {
        InitializeComponent();
        txtNum.Text = _numValue.ToString();
    }

    private void cmdUp_Click(object sender, RoutedEventArgs e)
    {
        NumValue++;
    }

    private void cmdDown_Click(object sender, RoutedEventArgs e)
    {
        NumValue--;
    }

    private void txtNum_TextChanged(object sender, TextChangedEventArgs e)
    {
        if (!int.TryParse(txtNum.Text, out _numValue))
            txtNum.Text = _numValue.ToString();
    }
Michael