INotifyPropertyChanged entre une page et un user control
Bonjour,
Quasiment tout est dans le titre. J'ai un user control qui contient et affiche différentes Pages via un navigation:Frame. Dans ma page je récupère un event en cas d'erreur que je souhaite remonter jusqu'au user control. Pour ça j'ai mis en place une class INotifyPropertyChanged qui dans un 1er temps ne fait qu'afficher / masquer un TextBlock à l'aide de Visibility.Collapsed.
J'utilise depuis le userControl le INotifyPropertyChanged pour l'initialisation en mode Collapsed et là ça passe. Mais d'une fois que je suis sur la Page, la notification n'est pas transmise au userControl.
ici mon système de notifications
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| public class Property : INotifyPropertyChanged
{
private Visibility _actionVisible;
public Visibility ActionsVisible
{
get { return _actionVisible; }
set
{
_actionVisible = value;
Notification("ActionsVisible");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void Notification(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
} |
il est appelé comme ceci sur mon userControl :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
Property notif = new Property();
public Automation()
{
InitializeComponent();
this.DataContext = notif;
notif.PropertyChanged += new PropertyChangedEventHandler(notif_PropertyChanged);
notif.ActionsVisible = Visibility.Collapsed;
}
void notif_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
error.Text("Handled");
error.Show();
} |
j'ai également tenté de le binder depuis le xaml comme ceci
Code:
<TextBlock FontSize="18" Visibility="{Binding Path=ActionsVisible, UpdateSourceTrigger=PropertyChanged}" Foreground="#FFB70505" Height="34.286" Margin="244,544,0,0" Name="txtConnection" Text="Problèmes de connexion, veuillez patienter." VerticalAlignment="Top" HorizontalAlignment="Left" Width="393.715" />
Sur ma Page qui doit me faire remonter l’événement j'ai ça :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
Property property = new Property();
private void perteConnexion(string err)
{
if (err.Contains("NotFound"))
{
//debug
error.Text(Resource.ErrorConnection + err);
error.Show();
//modifie la propriété pour notifier le conteneur du changement d'état
property.ActionsVisible = Visibility.Visible;
}
} |
En l'état, je passe bien dans perteConnexion(), j'arrive bien dans le setter ActionsVisible mais aucun événement ne se déclenche dans le userControl pour modifier l'état du TextBlock!