首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AutoCAD自定义扩展WPF UpDown

AutoCAD自定义扩展WPF UpDown
EN

Stack Overflow用户
提问于 2016-02-10 21:31:15
回答 2查看 257关注 0票数 0

基于扩展的WPF工具包,我想创建自己的路线上的AutoCAD站的CommonNumericUpDown<Station>。这在一个独立的-WPF-App中运行得很好。如果我从磁盘上的任何地方将其通过网络加载到AutoCAD中,我会得到一个XamlParseException“该方法或操作未实现。”,但将我的dll放在AutoCAD安装目录中也可以很好地工作。另外,创建我自己的CommonNumericUpDown<Double>工作得也很好。该错误也只在设置UpDownBase的一个属性时出现。AutoCAD在哪里欺骗我?

这是我的代码。为了尽可能简化,我扩展了UpDownBase<T>

代码语言:javascript
复制
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);
        }
    }
}

Generic.xaml:

代码语言:javascript
复制
<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:

代码语言:javascript
复制
<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>
EN

回答 2

Stack Overflow用户

发布于 2016-02-11 15:59:33

下载并安装程序集,选择acad.exe进程,然后在关联菜单中的Properties....NET acad.exe选项卡中,检查加载了哪些程序集。可能有一个旧版本的,扩展的WPF工具包由另一个扩展加载。

您还可以使用Fuslogvw检查是否存在绑定问题。

票数 1
EN

Stack Overflow用户

发布于 2016-03-22 22:57:46

经过几天的尝试,我发现即使删除了扩展的WPF工具包,错误仍然存在。我还发现了以下问题:WPF 4.0 Application load error in some environments

我的同事通过附加到AppDomain.CurrentDomain.AssemblyResolve += ResolveAssembly;并返回Assembly.LoadFile (assemblyPath);解决了这个问题

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35316653

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档