2009-05-06 123 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 

这些都触发​​事件,所以你有两个弹出窗口。如果您删除“点击=”或“手柄”,则只会触发一次事件。