模棱两可的类型引用.名为“VisualState”的类型至少出现在两个名称空间中



下面是什么错误?

类型引用有歧义。一个名为"VisualState"的类型至少出现在两个命名空间中:System。"Windows"one_answers"System.Windows"。考虑调整程序集XmlnsDefinition属性。

用户控件:

<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>

主窗口:

<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>

当使用两个或多个包含相同命名空间和类的引用时,会发生此错误(大多数情况下是警告)。在你的情况下,你正在使用VisualState,这是PresentationFramework程序集的一部分,你可能已经添加了另一个程序集,其中包含相同的"VisualState"对象,具有相同的命名空间"System"。窗口"。

您可以在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>

相关内容

最新更新