【问题标题】:Silverlight / Expression: XAML build errorSilverlight / 表达式:XAML 生成错误
【发布时间】:2010-10-14 18:05:13
【问题描述】:

我收到以下错误:

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>

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

【问题讨论】:

    标签: silverlight xaml expression-blend


    【解决方案1】:

    您是否碰巧在 Newsreader.StoryList 的其他地方(例如 StoryList.cs)中定义了“_contentLoaded”和“InitializeComponent”?

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

    【讨论】:

      【解决方案2】:

      我在从别人的代码中复制 ResourceDictionary 时遇到了这个问题。

      在我的例子中,我发现在源 ResourceDictionary 中有人定义了一个 x:Class 名称。编译器试图在同一个对象中混合源和复制,因此出现错误。

      【讨论】:

        【解决方案3】:
        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.
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2015-10-10
          • 2014-08-17
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多