2010-09-22 148 views
1

我一直需要使用数字上下控制我的WPF应用程序。我在这里发布了一个类似的问题,并尝试使用此处提供的那个>http://bot.codeplex.com/WPF数字上下自定义控件

我增加了引用,并在我的XAML窗口

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

引用它,这样做。

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

并不断收到错误:'nud'是一个未申报的namepsace。

我很新的WPF,所以任何帮助,将不胜感激。

+0

如果你得到那个错误,那么在你的代码中有一个'nud'引用。找到它并删除它或将其更改为'lib'。 – 2010-09-22 10:17:55

+0

搜索整个项目''未找到',但没有找到任何匹配项。 – 2010-09-22 10:38:21

+2

将项目(源代码)添加到您的应用程序(而不是引用它),然后尝试调试控件初始化程序。你可能会得到更具体的错误。 – akjoshi 2010-09-22 11:38:15

回答

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

enter image description here

当滚动条(或文本框)有焦点,滚动元素是可见的。在失去焦点时,只能看到文本框。只有滚动条可以在任何代码后面访问。