基于 Extended WPF Toolkit 我想为CommonNumericUpDown<Station>
沿路线的 AutoCAD 站创建自己的。这在 StandAlone-WPF-App 中工作得很好。如果我从磁盘上的任何位置在 AutoCAD 中对其进行网络加载,我会收到 XamlParseException“方法或操作未实现。”,但是将我的 dll 放在 AutoCAD-install-directory 中也可以正常工作。CommonNumericUpDown<Double>
还可以很好地创作我自己的作品。该错误也只会在设置 UpDownBase 的属性之一时出现。AutoCAD 在哪里欺骗我?
这是我的代码。为了尽可能简化,我扩展了UpDownBase<T>
.
using System;
using System.Windows;
using Xceed.Wpf.Toolkit.Primitives;
using Autodesk.AutoCAD.Runtime;
namespace My.AutoCAD.UITest
{
class UpDownBaseDoubleUpDown : UpDownBase<double>
{
protected override double ConvertTextToValue(string text)
{
return double.Parse(text);
}
protected override string ConvertValueToText()
{
return Value.ToString();
}
protected override void OnDecrement()
{
Value -= 1;
}
protected override void OnIncrement()
{
Value += 1;
}
protected override void SetValidSpinDirection() { }
static UpDownBaseDoubleUpDown()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(UpDownBaseDoubleUpDown), new FrameworkPropertyMetadata(typeof(UpDownBaseDoubleUpDown)));
}
}
public struct Station : IFormattable, IComparable<Station>
{
public double Value { get; set; }
public Station(double value) { Value = value; }
public int CompareTo(Station other)
{
return Value.CompareTo(other.Value);
}
public static Station Parse(string s) { return new Station(double.Parse(s)); }
public override string ToString() { return Value.ToString(); }
public string ToString(string format, IFormatProvider formatProvider)
{
return Value.ToString(format, formatProvider);
}
}
public class UpDownBaseStationUpDown : UpDownBase<Station>
{
protected override Station ConvertTextToValue(string text)
{
return Station.Parse(text);
}
protected override string ConvertValueToText()
{
return Value.ToString();
}
protected override void OnDecrement()
{
Value = new Station(Value.Value - 1);
}
protected override void OnIncrement()
{
Value = new Station(Value.Value + 1);
}
protected override void SetValidSpinDirection() { }
static UpDownBaseStationUpDown()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(UpDownBaseStationUpDown), new FrameworkPropertyMetadata(typeof(UpDownBaseStationUpDown)));
}
}
/// <summary>Interaction logic for StationUpDownTest.xaml</summary>
public partial class StationUpDownTest : Window
{
public StationUpDownTest()
{
InitializeComponent();
}
}
public class Commands
{
[CommandMethod("TestMgdStationUpDown")]
public void TestMgdStationUpDown()
{
var dlg = new StationUpDownTest();
Autodesk.AutoCAD.ApplicationServices.Core.Application.ShowModalWindow(dlg);
}
}
}
通用的.xaml:
<ResourceDictionary 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:local="clr-namespace:My.AutoCAD.UITest"
xmlns:core="clr-namespace:Xceed.Wpf.Toolkit.Core;assembly=Xceed.Wpf.Toolkit"
>
<ResourceDictionary.MergedDictionaries>
<core:VersionResourceDictionary AssemblyName="Xceed.Wpf.Toolkit" SourcePath="NumericUpDown/Themes/Generic.xaml" />
</ResourceDictionary.MergedDictionaries>
<Style TargetType="local:UpDownBaseStationUpDown" BasedOn="{StaticResource NumericUpDown}" />
<Style TargetType="local:UpDownBaseDoubleUpDown" BasedOn="{StaticResource NumericUpDown}" />
</ResourceDictionary>
StationUpDownTest.xaml:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:My.AutoCAD.UITest"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" x:Class="My.AutoCAD.UITest.StationUpDownTest"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<!-- doesn't work -->
<local:UpDownBaseStationUpDown HorizontalAlignment="Left" Margin="55,106,0,0" VerticalAlignment="Top" Width="136" Height="47"
AllowSpin="False"
/>
<!-- works -->
<local:UpDownBaseDoubleUpDown HorizontalAlignment="Left" Margin="55,106,0,0" VerticalAlignment="Top" Width="136" Height="47"
AllowSpin="False"
/>
</Grid>
</Window>