Quantcast
Viewing all articles
Browse latest Browse all 18858

How Do I access a timer declared in the MainWindow from a UserControl?--WPF Question

I am using a timer to plot points in time.  I am trying to clean up my project and create all controls I made in mainWindow.xaml as UserControls.  One control I have is a timer control.  It has some buttons that start and stop the timer.  What can I do to access the timer in the MainWindow.xaml.vb in my UserControl.xaml.vb.

Here is the timer declaration:

Class MainWindow
    Public WithEvents timer As New Windows.Threading.DispatcherTimer()

...

Here is some of the MainWindow xaml:

...<!--Place Controls Here--><local:CalcTool HorizontalAlignment="Left" VerticalAlignment="Bottom" x:Name="CalculatorTool"
                        Visibility="Hidden"/><local:TimerTool HorizontalAlignment="Left" VerticalAlignment="Bottom" x:Name="TimerControlTool"
                         Visibility="Hidden"/></Grid></Window>

Here is the UserControl.xaml.vb:

Public Class TimerTool
    'Public Main As MainWindow

    Private Sub StartBtn_Click(sender As Object, e As RoutedEventArgs) Handles StartBtn.Click
        'Need to somehow timer.start() here, but how?
    End Sub
End Class

I am not sure if this can be done.  I know this is a problem with how the threading is setup.  Is there something I can do to make the TimerTool a UserControl or do I need to keep it in the MainWindow.xaml?  Thanks.   

Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>