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

Extented WPF Toolkit にはNumericUpDownがあります。 ここに画像の説明を入力

于 2011-03-17T03:25:43.313 に答える
1

バニラ 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 に答える