Bonjour

Je suis entrain de suivre un tutoriel sur SilverLight permettant de créer une galerie d'images.

Je travailles sous Visual Studio 2010 (Difficile de dire si cela vient d'un bug du à la beta..).

Je rencontre l'erreur suivante lors de la compilation (ou pour afficher le designer) :
Error 1 Cannot register duplicate Name 'mainController' in this scope. C:\Users\Julien\Documents\Visual Studio 10\Projects\SilverlightApplication2\SilverlightApplication2\Page.xaml 10 27 SilverlightApplication2
Je vous remercie pour vos futures réponses,

Cdt
Julien

Voici les différentes pages de code :

Code xaml : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<UserControl x:Class="SilverlightApplication2.Page"
    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"
    xmlns:o="clr-namespace:SilverlightApplication2" 
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
    <UserControl.Resources>
        <o:MainController x:Name="mainController" />
        <o:ListImageObj x:Name="Images">
            <o:ImageObj id="1" titre="Coucou" url="ig2i.png" rating="3" ></o:ImageObj>
            <o:ImageObj id="2" titre="Salut" url="bodycote-logo.jpg" rating="3" ></o:ImageObj>
        </o:ListImageObj>
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot" Background="White">

        <StackPanel Orientation="Horizontal">
            <ListBox x:Name="lb1" ItemsSource="{StaticResource Images}" SelectedItem="{Binding Path=ImageSelected,Source={StaticResource mainController},Mode=TwoWay}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding titre}" />
                    </DataTemplate>
                   
                </ListBox.ItemTemplate>
            </ListBox>
            <Button  Margin="50" x:Name="bt1">
                <Button.Content>
                    <StackPanel>

                <TextBlock x:Name="tb1" HorizontalAlignment="Center" Text="{Binding Path=ImageSelected.titre,Source={StaticResource mainController}}"/>      
                <Image x:Name="image1" Height="106.656" Width="183.315" Source="{Binding Path=ImageSelected.url, Source={StaticResource mainController}}"  />
            </StackPanel>
              
          </Button.Content>
        </Button>
         </StackPanel>
    </Grid>
</UserControl>

Code c# : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
namespace SilverlightApplication2
{
    public class ImageObj
    {
        public int id { get; set; }
        public string titre { get; set; }
        public string url { get; set; }
        public int rating { get; set; }
 
    }
 
    public class ListImageObj : List<ImageObj>
    {
    }
 
}

Code c# : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;
namespace SilverlightApplication2
{
    public class MainController : INotifyPropertyChanged
    {
        private ImageObj imageSelected;
        public ImageObj  ImageSelected
        {
            get { return imageSelected; }
            set
            {
                if (imageSelected != value)
                {
                    imageSelected = value;
                    OnPropertyChanged("MyProperty");
                }
            }
 
        }
 
 
        #region INotifyPropertyChanged Members
        public event PropertyChangedEventHandler PropertyChanged;
        protected void OnPropertyChanged(string propertyName)
        {
 
            if (this.PropertyChanged != null)
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
 
        }
        #endregion
    }
}