WPF DecimalUpDown 自定义模板 NullReferenceException
WPF DecimalUpDown custom template NullReferenceException
我试图从 WPF 扩展工具包修改 DecimalUpDown 控件的外观,但每次我尝试为其创建模板时,我都会在 运行 时收到 NullReferenceException。
当然后不起作用时,我尝试尽可能基本并使用了这个:
<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()
我的模板中似乎缺少一些强制性的东西,但我不知道它是什么。有人可以帮忙吗?
如果你也能让我知道如何定义我可以应用于所有 up/down 控件的样式(我也在我的应用程序中使用 IntegerUpDown)那么我将非常感激。
提前致谢
我使用的是旧版本的工具包。下载最新版本后,它现在似乎可以工作了。感谢 Tanis83 的建议。
我试图从 WPF 扩展工具包修改 DecimalUpDown 控件的外观,但每次我尝试为其创建模板时,我都会在 运行 时收到 NullReferenceException。
当然后不起作用时,我尝试尽可能基本并使用了这个:
<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()
我的模板中似乎缺少一些强制性的东西,但我不知道它是什么。有人可以帮忙吗?
如果你也能让我知道如何定义我可以应用于所有 up/down 控件的样式(我也在我的应用程序中使用 IntegerUpDown)那么我将非常感激。
提前致谢
我使用的是旧版本的工具包。下载最新版本后,它现在似乎可以工作了。感谢 Tanis83 的建议。