2009-05-06 6 views
0

我在後端使用sliverlight 2.0中的openFileDialog和vb.net。我把它連接起來,它的工作原理是假設點擊事件似乎是兩次觸發。它首次啓動,我選擇文件並單擊確定。它處理。但只要我點擊確定,點擊事件第二次觸發,對話框再次出現。這不是我想要的,我不確定我做錯了什麼,它第二次出現。這是代碼..希望有人看到我做錯了什麼。Silverlight OpenFileDialog第二次打開

<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 

感謝 香

回答

0

我想這是因爲你註冊的事件兩次:你有它的按鍵定義:

Click="bOpenFileDialog_Click" 

,並在方法定義:

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

這些都觸發​​事件,所以你有兩個彈出窗口。如果您刪除「點擊=」或「手柄」,則只會觸發一次事件。

相關問題