User Tools

Site Tools


technical_notes:public:20131009-wpf-conflict-visual-states

Parent

WPF - Conflict with visual state (.Net 4)

This problem is automatically resolved by the version 4.5 of .Net Framework, even if you target v4.

You will get this error message :

Controls\CustomDatePicker.xaml (37): The type 'System.Windows.VisualState' exists in both 'c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\PresentationFramework.dll' and 'c:\Projets\CustomDatePicker\Sources\packages\WPFToolkit.3.5.50211.1\lib\WPFToolkit.dll'

To resolve the issue, open your xaml file :

<UserControl x:Class="Controls.CustomDatePicker"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
 
	<Grid>
		<DatePicker Grid.Column="1" />
		<VisualStateManager.VisualStateGroups>
            <VisualStateGroup Name="ValidationStates">
                <VisualState Name="Valid" />
                <VisualState Name="InvalidUnfocused">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames
                                            Storyboard.TargetProperty="Text"
                                            Storyboard.TargetName="DatePicker"
                                            Duration="0">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Text>Error</Text>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
	</Grid>
</UserControl>

We will get up the ambiguity using attribute header vsm.

<UserControl x:Class="Controls.CustomDatePicker"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:vsm ="clr-namespace:System.Windows;assembly=PresentationFramework">
 
    <Grid>
        <DatePicker Grid.Column="1" />
        <vsm:VisualStateManager.VisualStateGroups>
            <vsm:VisualStateGroup Name="ValidationStates">
                <vsm:VisualState Name="Valid" />
                <vsm:VisualState Name="InvalidUnfocused">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames
                                            Storyboard.TargetProperty="Text"
                                            Storyboard.TargetName="DatePicker"
                                            Duration="0">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Text>Error</Text>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </vsm:VisualState>
            </vsm:VisualStateGroup>
        </vsm:VisualStateManager.VisualStateGroups>
    </Grid>
</UserControl>
technical_notes/public/20131009-wpf-conflict-visual-states.txt · Last modified: 2013/10/09 11:28 by Fabien Arcellier