我打算通过按钮设置CalibrationGridControl的状态。 为此,CalibrationGridControl用户控件必须具有x:Name(在设置GoToState行为时,Blend甚至为我添加了一个。 问题是,一旦添加x:Name =“ calibrationGridControl”,我就会收到以下编译错误。
错误CS0426类型名称“ ViewModel”在类型“ TeachpendantControl”中不存在TeachPendantControl C:\ GitRepos \ SolutionName \ TheWPFControl \ Views \ HandeyeCalibration \ HandeyeCalibrationView.xaml 150 38构建活动编译器
下面的UserControl HandeyeCalibrationView是一个视图,将显示在“ TheWPFControl”的ContentControl内部。 WPFControl和HandyeCalibration.xaml都在同一项目中(WPF控件库)。下面是出现错误的HandeyeCalibration.xaml文件的重要部分。
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:TeachpendantControl.ViewModel"
xmlns:local="clr-namespace:TeachpendantControl.Views"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:b="clr-namespace:Wpf.Behaviours"
xmlns:HandeyeCalibration="clr-namespace:TeachpendantControl.ViewModel.H"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
x:Class="TeachpendantControl.Views.HandeyeCalibrationView"
mc:Ignorable="d"
d:DataContext ="{d:DesignInstance {x:Type vm:HandeyeCalibrationViewModel},
IsDesignTimeCreatable=True}"
Height="111.221"
Width="276.813"
>
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../../ResourceDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<UserControl.DataContext>
<Binding Mode="OneWay"
Path="HandeyeCalibrationViewModel"
Source="{StaticResource Locator2}"/>
</UserControl.DataContext>
<Grid>
<UserControl>
...
<HandeyeCalibration:CalibrationGridControl
x:Name="calibrationGridControl"
HorizontalAlignment="Left"
Margin="0"
VerticalAlignment="Top"
Height="106"
Width="106"
Background="#FF747474"/>
<Button Command="{Binding AddCommand}"
Content="{Binding AddText, UpdateSourceTrigger=PropertyChanged}"
Margin="0,0,5,0">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<ei:GoToStateAction TargetName="calibrationGridControl"
StateName="{Binding NextPositionState, Mode=OneWay}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
</Grid>
</UserControl>
如果仅删除x:Name =“ calibrationGridControl”行,则所有编译都可以。可能是什么错误导致此奇怪的错误消息?
我对CalibrationGridControl有一些疑问。如果我只是在将x:Name添加到另一个用户控件时将其删除,则所有内容都会编译。 CalibrationGridControl的XAML如下所示。
<UserControl x:Class="TeachpendantControl.ViewModel.H.CalibrationGridControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:TeachpendantControl.ViewModel"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity;assembly=System.Windows.Interactivity"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.Resources>
<SolidColorBrush x:Key="CalibrationGridCrossBrush" Color="#FFFFDF00"/>
<SolidColorBrush x:Key="CalibrationGridPositionTrainedFillBrush" Color="#FFFFDF00"/>
<SolidColorBrush x:Key="CalibrationGridPositionFillBrush" Color="Black"/>
</UserControl.Resources>
<Grid>
...
</Grid>
</UserControl>
答案 0 :(得分:1)
TeachpendantControl
显然是类型和的名称空间。
您应该更改控件的名称或更改名称空间的名称,以避免命名冲突。