web-dev-qa-db-ja.com

あいまいな型参照。 `VisualState`という名前のタイプは、少なくとも2つの名前空間で発生します

次のエラーは何ですか?

あいまいな型参照。 「VisualState」という名前のタイプは、少なくとも2つの名前空間「System.Windows」と「System.Windows」で発生します。 AssemblyXmlnsDefinition属性を調整することを検討してください。

UserControl:

<UserControl
    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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    x:Class="ButtonWPF.MyButtonAdd"
    x:Name="AddButton"
    d:DesignWidth="84" d:DesignHeight="87">
    <UserControl.Resources>
        <Style x:Key="ButtonStyle1" TargetType="{x:Type Button}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Grid x:Name="grid" RenderTransformOrigin="0.5,0.5">
                            <Grid.RenderTransform>
                                <TransformGroup>
                                    <ScaleTransform/>
                                    .............
                                    <Trigger Property="IsDefaulted" Value="True"/>
                                    <Trigger Property="IsMouseOver" Value="True"/>
                                    <Trigger Property="IsPressed" Value="True"/>
                                    <Trigger Property="IsEnabled" Value="False"/>
                                    </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot"
          Height="79"
          Width="72">
        <Button Content=""
                HorizontalAlignment="Left"
                Height="61"
                Style="{DynamicResource ButtonStyle1}"
                VerticalAlignment="Top"
                Width="57"/>
    </Grid>
</UserControl>

MainWindow:

<Window x:Class="ButtonWPF.MainWindow"
        xmlns="http://schemas.Microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.Microsoft.com/winfx/2006/xaml"
        xmlns:dg="http://schemas.Microsoft.com/wpf/2008/toolkit"
        xmlns:my="clr-namespace:ButtonWPF"
        Title="winGroup"
        Height="637"
        Width="638"
        FontSize="15"
        FontWeight="Bold">
    <Grid>
        <my:MyButtonAdd HorizontalAlignment="Left"
                        Margin="540,519,0,0"
                        x:Name="btnAdd"
                        VerticalAlignment="Top"
                        IsEnabled="True"/>
    </Grid>
</Window>
36
mrJack

このエラー(ほとんどの場合警告)は、同じ名前空間とクラスを含む2つ以上の参照を使用する場合に発生します。あなたの場合、PresentationFrameworkアセンブリの一部であるVisualStateを使用していて、同じ名前空間「System.Windows」を持つ同じ「VisualState」オブジェクトを含む別のアセンブリを追加した可能性があります。

xamlで次のインポートを使用してエラーを解決できます

xmlns:vsm ="clr-namespace:System.Windows;Assembly=PresentationFramework"

使用する代わりに

<VisualState x:Name="Pressed">
                                        <Storyboard>

                                        </Storyboard>
                                    </VisualState>

使用:

<vsm:VisualState x:Name="Pressed">
                                    <Storyboard>

                                    </Storyboard>
                                </vsm:VisualState>
50
Bathineni