WPF数字上下自定义控件
我一直需要为我的WPF应用程序使用数字上下控制。我在这里看到了一个类似的问题,并尝试使用此处提供的问题> 我添加了引用,并在我的XAML窗口中引用了它WPF数字上下自定义控件,wpf,wpf-controls,custom-controls,numericupdown,Wpf,Wpf Controls,Custom Controls,Numericupdown,我一直需要为我的WPF应用程序使用数字上下控制。我在这里看到了一个类似的问题,并尝试使用此处提供的问题> 我添加了引用,并在我的XAML窗口中引用了它 xmlns:lib="clr-namespace:PixelLab.Wpf;assembly=PixelLab.Wpf" 他做到了这一点 <lib:NumericUpDown Name="year"></lib:NumericUpDown> 并且不断得到错误:“nud”是一个未声明的名称 我对WPF非常陌生,因此非
xmlns:lib="clr-namespace:PixelLab.Wpf;assembly=PixelLab.Wpf"
他做到了这一点
<lib:NumericUpDown Name="year"></lib:NumericUpDown>
并且不断得到错误:“nud”是一个未声明的名称
我对WPF非常陌生,因此非常感谢您的帮助。扩展的WPF工具包有一个: 香草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();
}
}
}
使用System.Windows;
名称空间微调器{
公共部分类主窗口:System.Windows.Window{
公共主窗口(){
初始化组件();
}
}
}
当滚动条(或文本框)具有焦点时,滚动元素可见。失去焦点时,只有文本框可见。在任何代码隐藏中只能访问滚动条。只需将文本框与真正的固定高度滚动条组合起来,如下所示:
<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的绑定是直接可用的。如果出现该错误,那么代码中的某个地方引用了一个“nud”。找到并删除它或将其更改为“lib”。在整个项目中搜索“nud”,但未找到任何匹配项。将项目(源代码)添加到应用程序中(而不是引用它),然后尝试调试控件初始值设定项。这样可能会出现更具体的错误。创建一个新的(临时)WPF项目,将相同的引用添加到PixelLab库中,将引用添加到XAML中,然后将NumericUpDown添加到窗口中。看看它是否运行。如果它运行,那么它在项目中的某个地方就是一个问题。如果您得到相同的错误,可能是PixelLab库中的错误,因此您应该查看源代码。如果您在库中发现错误,请向他们报告,并在此处进行跟进,以便有相同问题的任何人受益。