Bonjour,

je suis a la recherche d'une solution pour un mon problème qui a l'air très simple, mais ou je ne panne rien au Binding WPF.


Donc, j'ai une DataGrid toute simple ou j'essai de mettre en place un RowDetailsTemplate, jusque la tout va bien. Dans ce RowDetailsTemplate je souhaite placé un UserControl (fait par moi), et biensur qu'il soit bindé a la donnée en cour.

La DataGrid :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
 
 <DataGrid SelectionMode="Single" IsReadOnly="True" x:Name="Patients" cal:Message.Attach="[Event SelectionChanged] = [Action Test($source,$eventArgs)]" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" AutoGenerateColumns="False"  Grid.Column="0" Grid.Row="0">
                <DataGrid.Columns>
                    <DataGridTextColumn Binding="{Binding Name}" Header="Name" Width="*"/>
                    <DataGridCheckBoxColumn Header="Activate" Width="50" IsThreeState="False" MinWidth="30" 
                                   Binding="{Binding Path=IsActivated, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                </DataGrid.Columns>
                <DataGrid.RowDetailsTemplate>
                    <DataTemplate>                        
                        <ui:PatientConfigurationGridTemplate PatientConfiguration="{Binding PatientConfiguration}" />
                    </DataTemplate>
                </DataGrid.RowDetailsTemplate>
            </DataGrid>

Le UserControl (Code behind)
Code : 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
 
public partial class PatientConfigurationGridTemplate : UserControl
    {
 
        public static readonly DependencyProperty PatientConfigurationProperty = 
            DependencyProperty.Register("PatientConfiguration", typeof(PatientConfiguration), typeof(PatientConfigurationGridTemplate), 
            new FrameworkPropertyMetadata (null,FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, new PropertyChangedCallback(OnPatientChanged)));
 
        private static void OnPatientChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            PatientConfigurationGridTemplate template = d as PatientConfigurationGridTemplate;
            if (template != null)
            {
                template.PatientChanged(d, e);
            }
 
        }
 
        private ImageResourceHolder _imageResourceHolder;
        private ImageResourceHolder GetImageResourceHolder
        {
            get
            {
                if (_imageResourceHolder == null)
                {
                    NinjectServiceLocator locator = (NinjectServiceLocator)ServiceLocator.Current;
                    _imageResourceHolder = locator.GetInstance<ImageResourceHolder>();
                }
                return _imageResourceHolder;
            }
        }
 
        public Patient PatientConfiguration
        {
            get
            {
                return (Patient)GetValue(PatientConfigurationProperty);
            }
            set
            {
                SetValue(PatientConfigurationProperty, value);
            }
        }
 
        private void PatientChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            PatientConfiguration configuration = e.NewValue as PatientConfiguration;
            if (configuration != null)
            {
 
                SacrumConfiguration.Source = GetImageForZone(configuration.GetSacrumConfiguration());
                SacrumConfiguration.UpdateLayout();
 
                LeftHeelConfiguration.Source = GetImageForZone(configuration.GetLeftHeelConfiguration());
                LeftHeelConfiguration.UpdateLayout();
 
                RigthHeelConfiguration.Source = GetImageForZone(configuration.GetRightHeelConfiguration());
                RigthHeelConfiguration.UpdateLayout();
 
                UpdateLayout();
            }
        }
 
 
        private BitmapFrame GetImageForZone(ZoneConfiguration zoneConf)
        {
 
            BitmapFrame image=null;
            switch (zoneConf.Setting)
            {
                case Setting.Low:
                    image = GetImageResourceHolder.GetBitmap("threshold_low");
                    break;
                case Setting.Medium:
                    image = GetImageResourceHolder.GetBitmap("threshold_medium");
                    break;
                case Setting.High:
                    image = GetImageResourceHolder.GetBitmap("threshold_high");
                    break;
            }
            return image;
        }
 
 
        public PatientConfigurationGridTemplate()
        {
            InitializeComponent();
 
            SacrumConfiguration.DataContext = this;
            LeftHeelConfiguration.DataContext = this;
            RigthHeelConfiguration.DataContext = this;
        }
    }
Bon le probleme, c'est que la DependencyProperty n'est jamais appelé, et du coup je n'ai rien dans les details.


Merci pour votre aide!