wpf VisualState conflicts with wpfToolkit?

五迷三道 提交于 2019-12-07 11:06:59

问题


I am building an application in VS2010 with wpfToolkit 3.5 as referenced assembly.

I tried to add some VisualStates from ExpressionBlend 4 and I am getting the following error when I am trying to build the project.

The type 'System.Windows.VisualState' exists in both 'c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\PresentationFramework.dll' and 'c:\Program Files (x86)\WPF Toolkit\v3.5.50211.1\WPFToolkit.dll'

this is the code

<VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="ShowHideRoomNumber">
            <VisualState x:Name="Show"/>
            <VisualState x:Name="Hide">
                <Storyboard>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="comboBox">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/>
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>

I tried also and this but the same error occured

xmlns:vsm="clr-namespace:System.Windows;assembly=WPFToolkit"

<vsm:VisualStateManager.VisualStateGroups>
        <vsm:VisualStateGroup x:Name="ShowHideRoomNumber">
            <vsm:VisualState x:Name="Show"/>
            <vsm:VisualState x:Name="Hide">
                <Storyboard>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="comboBox">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/>
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
            </vsm:VisualState>
        </vsm:VisualStateGroup>
    </vsm:VisualStateManager.VisualStateGroups>

Any suggestions?

Thanks


回答1:


This is what extern alias is for http://msdn.microsoft.com/en-us/library/ms173212.aspx

You can set this up through Visual studio by

  1. Right click on the WPFToolkit reference to view its properties,
  2. Change the "alias" field to anything you like.



回答2:


The way that I have resolved this problem is to get a copy of the source code here, and modify it so that the VisualStateManager and related classes are in a different namespace (I chose System.Windows.VSM) It is kind of a pain, but it will work. I expect that the VSM will be removed from future versions of the toolkit but I can't prove it.

Meanwhile, there are a couple of things other that you can do, and each of them are kind of a pain + probably won't work, depending on your case.

  1. Drop the dependency to WPFToolkit. Your code probably needs it, so this won't really work. I was lucky and got away with it on one of my projects.
  2. Wait for the next release of WPFToolkit, and hope it gets fixed. Who knows when this will happen, its been almost a year now.
  3. Use blend 3, or something else that is compatible with your version of the Toolkit.


来源:https://stackoverflow.com/questions/5108334/wpf-visualstate-conflicts-with-wpftoolkit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!