1

我正在尝试从 WPF Extended Toolkit 修改 DecimalUpDown 控件的外观,但每次尝试为其创建模板时,我都会在运行时收到 NullReferenceException。

我尝试使用此链接中的模板:https ://social.msdn.microsoft.com/Forums/vstudio/en-US/304c5191-687f-47b9-8924-56816647e2b4/im-using-the-wpf-extended-toolkit -singleupdown-control?forum=wpf

当那时不起作用时,我尝试尽可能基本并使用它:

<Style TargetType="{x:Type etk:DecimalUpDown}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="etk:DecimalUpDown">
                <etk:ButtonSpinner
                    Name="PART_Spinner">
                    <etk:WatermarkTextBox
                        Name="PART_TextBox" />
                </etk:ButtonSpinner>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

但是我两次都得到了 NullReferenceException 。堆栈跟踪是:

at Microsoft.Windows.Controls.Primitives.UpDownBase`1.OnApplyTemplate()
at System.Windows.FrameworkElement.ApplyTemplate()
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV, Boolean& hasDesiredSizeUChanged)
at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)
at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.Controls.Border.MeasureOverride(Size constraint)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.Window.MeasureOverrideHelper(Size constraint)
at System.Windows.Window.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.Interop.HwndSource.SetLayoutSize()
at System.Windows.Interop.HwndSource.set_RootVisualInternal(Visual value)
at System.Windows.Interop.HwndSource.set_RootVisual(Visual value)
at System.Windows.Window.SetRootVisual()
at System.Windows.Window.SetRootVisualAndUpdateSTC()
at System.Windows.Window.SetupInitialState(Double requestedTop, Double requestedLeft, Double requestedWidth, Double requestedHeight)
at System.Windows.Window.CreateSourceWindow(Boolean duringShow)
at System.Windows.Window.CreateSourceWindowDuringShow()
at System.Windows.Window.SafeCreateWindowDuringShow()
at System.Windows.Window.ShowHelper(Object booleanBox)
at System.Windows.Window.Show()
at System.Windows.Window.ShowDialog()

我的模板中似乎遗漏了一些强制性的东西,但我不知道它是什么。任何人都可以帮忙吗?

如果您还可以让我知道如何定义可以应用于所有向上/向下控件的样式(我也在我的应用程序中使用 IntegerUpDown),那么我将非常感激。

提前致谢

4

1 回答 1

0

我使用的是旧版本的工具包。下载最新版本后,它现在似乎可以工作了。感谢 Tanis83 提出这个建议。

于 2015-07-15T09:51:00.650 回答