Silverlight / Expression: XAML build error
I'm getting the following errors:
obj\Debug\StoryList.g.cs(40,22): error CS0102: The type 'Newsreader.StoryList' already contains a definition for '_contentLoaded'
obj\Debug\StoryList.g.cs(46,21): error CS0111: Type 'Newsreader.StoryList' already defines a member called 'InitializeComponent' with the same parameter types
Here is the 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"/>
</St开发者_如何转开发ackPanel>
</ScrollViewer>
</Grid>
What could I be doing wrong here? I was copying/pasting to create new controls. Could that possibly have something to do with it?
do you happen to have a '_contentLoaded' and 'InitializeComponent' defined elsewhere in Newsreader.StoryList (e.g. in StoryList.cs)?
If you open StoryList.g.cs and look at the generated code, you might be able to see the problem there.
I had this issue duplicating a ResourceDictionary from someone else's code.
In my case I discovered that in the source ResourceDictionary someone had defined an x:Class name. The compiler was trying to mash the source and duplicate together in the same object, hence the error.
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.
精彩评论