Bonjour,
Voici une solution trouvée, mais peut-être pas la plus académique.
Dans un module, j'ai déclaré une variable et un événement. La variable est visible de toutes les fenêtres.
Dans la fenêtre principale, je lie l'événement à ma fonction.
Quant on modifie la valeur de la variable, je déclenche l'événement et ma fonction est exécutée.
Ci-joint un exemple pour essai.
Existe-t-il d'autres solutions?
Jacky
<Window x:Name="MainWindow" x:Class="MainWindow"
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:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="187" Width="259">
<Grid>
<Label x:Name="lbEssai" Content="Label" HorizontalAlignment="Left" Margin="20,104,0,0" VerticalAlignment="Top" Width="195" Background="#FFC11818"/>
<Button Content="Ouverture Window2" HorizontalAlignment="Left" Height="55" Margin="20,20,0,0" VerticalAlignment="Top" Width="140" Click="Button_Click" RenderTransformOrigin="-1.286,1.091"/>
</Grid>
</Window>
<Window x:Name="Window2" x:Class="Window2"
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:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="Window2" Height="227" Width="329">
<Grid>
<Button Content="Evénément sur MainWindow
Changement content label" HorizontalAlignment="Left" Height="80" Margin="60,40,0,0" VerticalAlignment="Top" Width="200" Click="Button_Click"/>
</Grid>
</Window>
Module Module1
Property PageActive As Byte
Get
Return m_PageActive
End Get
Set(ByVal value As Byte)
If m_PageActive <> value Then
m_PageActive = value
'Déclenche l'événement
RaiseEvent PageActiveEvent(value)
End If
End Set
End Property
'Déclaration de l'événement
Public Event PageActiveEvent(ByVal Numpage As Byte)
Dim m_PageActive As Byte
End Module
Class MainWindow
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
'Affiche la 2ème fenêtre
Dim wdWindow2 As Window2 = New Window2
wdWindow2.Show()
End Sub
Private Sub MainWindow_Loaded(sender As Object, e As RoutedEventArgs) Handles MyBase.Loaded, MyBase.Loaded
'Associe l'événement du module
AddHandler Module1.PageActiveEvent, AddressOf ActivePageEvent
End Sub
Sub ActivePageEvent(ByVal Numpage As Byte)
'Affiche la page
lbEssai.Content = Numpage
End Sub
End Class
Public Class Window2
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
'Attribue la page active
PageActive = 1
End Sub
End Class