Silverlight / Expression:XAML构建错误

时间:2010-10-14 18:05:13

标签: silverlight xaml expression-blend

我收到以下错误:

  

obj \ Debug \ StoryList.g.cs(40,22):错误   CS0102:类型   'Newsreader.StoryList'   已经包含了一个定义   '_contentLoaded'

     

obj \ Debug \ StoryList.g.cs(46,21):错误   CS0111:输入   'Newsreader.StoryList'   已定义一个名为的成员   'InitializeComponent'与之相同   参数类型

这是XAML:

<Grid x:Name="MyLayoutRoot" Background="Transparent">
    <ScrollViewer d:LayoutOverrides="Height" HorizontalAlignment="Left" Width="424">
        <StackPanel Height="865">
            <local:StoryControl Height="206" HorizontalAlignment="Left">
                <Custom:Interaction.Triggers>
                    <Custom:EventTrigger EventName="MouseLeftButtonDown">
                        <ic:NavigateToPageAction TargetPage="/StoryPage.xaml"/>
                    </Custom:EventTrigger>
                </Custom:Interaction.Triggers>
            </local:StoryControl>
            <local:StoryControl Height="206" HorizontalAlignment="Left">
                <Custom:Interaction.Triggers>
                    <Custom:EventTrigger EventName="MouseLeftButtonDown">
                        <ic:NavigateToPageAction TargetPage="/StoryPage.xaml"/>
                    </Custom:EventTrigger>
                </Custom:Interaction.Triggers>
            </local:StoryControl>
            <local:StoryControl Height="206" HorizontalAlignment="Left">
                <Custom:Interaction.Triggers>
                    <Custom:EventTrigger EventName="MouseLeftButtonDown">
                        <ic:NavigateToPageAction TargetPage="/StoryPage.xaml"/>
                    </Custom:EventTrigger>
                </Custom:Interaction.Triggers>
            </local:StoryControl>
            <local:StoryControl Height="206" HorizontalAlignment="Left"/>
        </StackPanel>
    </ScrollViewer>
</Grid>

我在这里做错了什么?我正在复制/粘贴以创建新控件。这可能与它有关吗?

3 个答案:

答案 0 :(得分:0)

你碰巧在Newsreader.StoryList的其他地方定义了'_contentLoaded'和'InitializeComponent'(例如在StoryList.cs中)吗?

如果您打开StoryList.g.cs并查看生成的代码,您可能会在那里看到问题。

答案 1 :(得分:0)

我有这个问题从别人的代码复制ResourceDictionary。

在我的情况下,我发现在源ResourceDictionary中有人定义了一个x:Class名称。编译器试图将源混合并在同一对象中复制在一起,因此出错。

答案 2 :(得分:0)

Below could be one of the reason.
When you copy existing control to create new one, you seems forgot to update x:Class.
For example see below two controls pointing to same partial class.
 
//StoryList.xaml
<UserControl x:Class="Newsreader.StoryList"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             . . . 
             Title=" StoryList"
             Height="194" Width="450">

//AnotherFile.xaml
<UserControl x:Class="Newsreader.StoryList"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             . . . 
             Title="AnotherFile"
             Height="120" Width="320">

Change in AnotherFile.xaml  as x:Class="Newsreader.AnotherFile" 
You should be fine.