我在后端使用sliverlight 2.0中的openFileDialog和vb.net。我把它连接起来并且它正在工作,因为它假设除了click事件似乎发射两次。它第一次触发,我选择文件并单击确定。它进行处理。但是一旦我点击确定,点击事件就会再次触发,对话框会再次出现。这不是我想要的,我不知道我第二次出现的错误。这是代码..希望有人看到我做错了什么。
<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 :(得分:0)
我认为这是因为你注册了两次事件:你在按钮定义中有它:
Click="bOpenFileDialog_Click"
并在方法定义中:
Private Sub bOpenFileDialog_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles bOpenFileDialog.Click
每个触发事件,因此您有两个弹出窗口。如果您删除“Click =”或“handle”,您将只触发一次事件。