Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将x:Name添加到用户控件会导致其所用页面的生成代码出错_C#_Wpf_Vb.net_Silverlight_User Controls - Fatal编程技术网

C# 将x:Name添加到用户控件会导致其所用页面的生成代码出错

C# 将x:Name添加到用户控件会导致其所用页面的生成代码出错,c#,wpf,vb.net,silverlight,user-controls,C#,Wpf,Vb.net,Silverlight,User Controls,我基本上是第一次使用用户控件,所以希望这只是一个愚蠢的错误 我有一个简单的用户控件 <UserControl x:Class="TestProject.WebApp.myUserControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://

我基本上是第一次使用用户控件,所以希望这只是一个愚蠢的错误

我有一个简单的用户控件

<UserControl x:Class="TestProject.WebApp.myUserControl"
    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"
    xmlns:riaControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.DomainServices"
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">

    <Grid>
        <sdk:AutoCompleteBox Name="myACB" ItemsSource="{Binding Data}" FilterMode="StartsWith" MinimumPrefixLength="2" >
        </sdk:AutoCompleteBox>
    </Grid>
</UserControl>
我尝试了两种不同的控制。同样的事情。生成的代码有“using TestProject.WebApp;”,所以我不知道为什么只有当我有一个控件的命名实例时才会出现错误


我似乎也不能仅仅使用Name属性。我甚至尝试在控件中重载NameProperty。

这里显示的内容应该可以工作。项目属性的默认命名空间是什么?在创建用户控件之后,您是否重命名了它。这两个问题都可能给您带来问题。

我在这里找到了一篇关于这一点的帖子:

显然,当一个项目有一个服务引用(在我的例子中,我使用的是RIA服务)并且用户控件驻留在一个与您尝试使用它的名称空间具有相同根名称空间的程序集中时,就会出现问题

所以对我来说

TestProject.WebApp

然后我尝试为控件创建一个新项目

TestProject.Controls

同样的问题

然后,当我重命名项目并将名称空间更改为

自定义控件

成功了


希望这能让其他人免于一些挫折,我真的希望微软能尽快解决这个问题。

该项目的名称空间是TestProject.WebApp。我从未重命名过该控件,但在解决方案中更改了几个项目的名称空间。但是,我只是尝试为我的自定义控件创建一个新项目,添加了对新项目的引用,并向页面添加了该控件的实例。我在尝试使用x:Name属性时也遇到了同样的错误。我很高兴你发现了,这是一个奇怪的错误
<navigation:Page x:Class="TestProject.WebApp.myPageView" 
           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"
           xmlns:local="clr-namespace:TestProject.WebApp"
           xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation">
    <Grid>
        <StackPanel Orientation="Horizontal">
            <local:myUserControl x:Name="myUC" />
        </StackPanel>
    </Grid>
</navigation:Page>
internal TestProject.WebApp.myUserControl myUC;

this.myUC == (TestProject.WebApp.myUserControl)this.FindName("myUC")