0

我打算从一个按钮设置 CalibrationGridControl 的状态。为此,CalibrationGridControl UserControl 必须具有 ax: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>
4

1 回答 1

1

TeachpendantControl显然既是类型是命名空间。

您应该更改控件​​的名称或更改命名空间的名称以避免命名冲突。

于 2018-08-29T13:34:17.130 回答