1

我一直需要为我的 WPF 应用程序使用数字上下控件。我阅读了此处发布的类似问题,并尝试使用此处提供的问题 > http://bot.codeplex.com/

我添加了引用并在我的 XAML 窗口中引用了它

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

并做到了这一点。

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

并不断收到错误:“nud”是一个未声明的命名空间。

我对 WPF 非常陌生,因此将不胜感激。

4

3 回答 3

2

扩展的 WPF 工具包有一个:NumericUpDown 在此处输入图像描述

于 2011-03-17T03:25:43.313 回答
1

只需将 TextBox 与垂直的固定高度 ScrollBar 结合起来,如下所示:

<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>

在此处输入图像描述

最大、最小和 SmallChange/Increment 的绑定是直接可用的。

于 2020-05-08T03:16:41.297 回答
1

Vanilla XAML(无添加或包)实现:

    <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();
            }
        }
    }

在此处输入图像描述

当滚动条(或文本框)具有焦点时,滚动元素可见。失去焦点时,只有文本框可见。在任何代码隐藏中只能访问滚动条。

于 2016-10-13T14:45:04.573 回答