Silverlight OpenFileDialog opens a second time

I am using openFileDialog in sliverlight 2.0 with vb.net at the end. I hooked it up and it works as expected, except that the click event seems to fire twice. It starts the first time, I select the files and click ok. it does the processing. But as soon as I click ok, the click event fires a second time and the dialog reappears. this is not what I want and I am not sure what I am doing wrong, this is happening a second time. Here is the code .. hope someone takes a look at what I am doing wrong.

<Button x:Name="bOpenFileDialog" Content="2. Import CSV"
             Height="30" Width="200" Margin="0,96,0,0"
             HorizontalAlignment="Left" VerticalAlignment="Top" 
             Click="bOpenFileDialog_Click" />
    <TextBlock Height="19" Margin="246,26,261,0" VerticalAlignment="Top" Text="TextBlock" TextWrapping="Wrap" x:Name="lblMsg"/>

 Private Sub bOpenFileDialog_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles bOpenFileDialog.Click
    Me.bOpenFileDialog.IsEnabled = False
    ' Create an instance of the open file dialog box.
    Dim openFileDialog1 As OpenFileDialog = New OpenFileDialog


    ' Set filter options and filter index.
    openFileDialog1.Filter = "LOG Files (*.log)|*.log|All Files (*.*)|*.*"
    openFileDialog1.FilterIndex = 1

    openFileDialog1.Multiselect = True

    ' Call the ShowDialog method to show the dialogbox.
    Dim UserClickedOK As Boolean = CBool(openFileDialog1.ShowDialog)

    ' Process input if the user clicked OK.
    If (UserClickedOK = True) Then
        Dim rows As Integer = openFileDialog1.Files.Count - 1
        ReDim aryIISLogs(rows)

        For i As Integer = 0 To openFileDialog1.Files.Count - 1
            aryIISLogs(i) = openFileDialog1.Files(i).Name
        Next
        Process1File()
    End If
End Sub

      

Thanks Shannon

0


a source to share


1 answer


I think this is because you are registering the event twice: you have it in the button definition:

Click="bOpenFileDialog_Click" 

      

and in the method definition:



Private Sub bOpenFileDialog_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles bOpenFileDialog.Click

      

Each of these triggers an event, so you have two popups. If you remove "Click =" or "handle", you will receive the event only once.

0


a source







All Articles