Hi, I've created a RecordNavigation UserControl (xaml and vb.net) and implemented bubbling RoutedEvents for each of the buttons.
Public Shared GotoFirstEvent As RoutedEvent = EventManager.RegisterRoutedEvent("GotoFirst", RoutingStrategy.Bubble, GetType(RoutedEventHandler), GetType(adeptXRecordNavigationControl)) Public Custom Event GotoFirst As RoutedEventHandler AddHandler(value As RoutedEventHandler) Me.AddHandler(GotoFirstEvent, value) End AddHandler RemoveHandler(value As RoutedEventHandler) Me.RemoveHandler(GotoFirstEvent, value) End RemoveHandler RaiseEvent(sender As Object, e As System.Windows.RoutedEventArgs) Me.RaiseEvent(e) End RaiseEvent End Event Private Sub RaiseGotoFirstEvent() Dim eventArgs As New RoutedEventArgs(adeptXRecordNavigationControl.GotoFirstEvent) MyBase.RaiseEvent(eventArgs) End Sub Private Sub btnGotoFirst_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Me.RaiseGotoFirstEvent() End Sub
I've created a ResourceDictionary (all xaml) to restyled DataGrid (called customDataGridStyle). I've placed the RecordNavigation UserControl inside the DataGrid (x:Name="RecordNavigation").
I can now restyle any DataGrid:
<ResourceDictionary.MergedDictionaries><ResourceDictionary Source="/MyProject;component/Resources/customDataGridResourceDictionary.xaml" /></ResourceDictionary.MergedDictionaries><DataGrid x:Name="dgClient" Style="{StaticResource customDataGridStyle}" ><DataGrid.Columns><DataGridTextColumn Header="Forename" Width="80" Binding="{Binding Path=Forename}" /><DataGridTextColumn Header="Surname" Width="80" Binding="{Binding Path=Surname}" /></DataGrid.Columns></DataGrid>
How can I capture events from the UserControl in the hosting Window?
Thanks, Graeme