次のエラーは何ですか?
あいまいな型参照です。'VisualState' という名前の型が、少なくとも 2 つの名前空間 ('System.Windows' と '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>
ベストアンサー1
このエラー (ほとんどの場合は警告) は、同じ名前空間とクラスを含む 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>