2010-08-13 3 views
1

아무도 내가 이것을 vb.net으로 변환하는 데 도움이 될 수 있습니까? 나는 올바르게 작동하지 않았고 그것을 변환하는 방법을 모른다.C#에서 VB 로의 변환 질문

public Person CurrentPersonCancellable 
    { 
     get 
     { 
      Debug.WriteLine("Getting CurrentPersonCancellable."); 
      return _CurrentPersonCancellable; 
     } 
     set 
     { 
      // Store the current value so that we can 
      // change it back if needed. 
      var origValue = _CurrentPersonCancellable; 

      // If the value hasn't changed, don't do anything. 
      if (value == _CurrentPersonCancellable) 
       return; 

      // Note that we actually change the value for now. 
      // This is necessary because WPF seems to query the 
      // value after the change. The combo box 
      // likes to know that the value did change. 
      _CurrentPersonCancellable = value; 

      if (
       MessageBox.Show(
        "Allow change of selected item?", 
        "Continue", 
        MessageBoxButton.YesNo 
       ) != MessageBoxResult.Yes 
      ) 
      { 
       Debug.WriteLine("Selection Cancelled."); 

       // change the value back, but do so after the 
       // UI has finished it's current context operation. 
       Application.Current.Dispatcher.BeginInvoke(
         new Action(() => 
         { 
          Debug.WriteLine(
           "Dispatcher BeginInvoke " + 
           "Setting CurrentPersonCancellable." 
          ); 

          // Do this against the underlying value so 
          // that we don't invoke the cancellation question again. 
          _CurrentPersonCancellable = origValue; 
          OnPropertyChanged("CurrentPersonCancellable"); 
         }), 
         DispatcherPriority.ContextIdle, 
         null 
        ); 

       // Exit early. 
       return; 
      } 

      // Normal path. Selection applied. 
      // Raise PropertyChanged on the field. 
      Debug.WriteLine("Selection applied."); 
      OnPropertyChanged("CurrentPersonCancellable"); 
     } 
    } 

변환기를 사용하면이 문제를 해결할 수 있습니다. 문제는 응용 프로그램을 호출하는 곳에서 발생합니다. 현재. 디스패처. 시작. 여러 문을 포함 할 수 없습니다 BeginInvoke에서 사용

Public Property CurrentPersonCancellable() As Person 
Get 
    Debug.WriteLine("Getting CurrentPersonCancellable.") 
    Return _CurrentPersonCancellable 
End Get 
Set 
    ' Store the current value so that we can 
    ' change it back if needed. 
    Dim origValue = _CurrentPersonCancellable 

    ' If the value hasn't changed, don't do anything. 
    If value = _CurrentPersonCancellable Then 
     Return 
    End If 

    ' Note that we actually change the value for now. 
    ' This is necessary because WPF seems to query the 
    ' value after the change. The combo box 
    ' likes to know that the value did change. 
    _CurrentPersonCancellable = value 

    If MessageBox.Show("Allow change of selected item?", "Continue", MessageBoxButton.YesNo) <> MessageBoxResult.Yes Then 
     Debug.WriteLine("Selection Cancelled.") 

     ' change the value back, but do so after the 
     ' UI has finished it's current context operation. 
     Application.Current.Dispatcher.BeginInvoke(New Action(Function() Do 
      Debug.WriteLine("Dispatcher BeginInvoke " + "Setting CurrentPersonCancellable.") 

      ' Do this against the underlying value so 
      ' that we don't invoke the cancellation question again. 
      _CurrentPersonCancellable = origValue 
      OnPropertyChanged("CurrentPersonCancellable") 
     End Function), DispatcherPriority.ContextIdle, Nothing) 

     ' Exit early. 
     Return 
    End If 

    ' Normal path. Selection applied. 
    ' Raise PropertyChanged on the field. 
    Debug.WriteLine("Selection applied.") 
    OnPropertyChanged("CurrentPersonCancellable") 
End Set 
End Property 
+4

작업을 수행하도록 요청하지 않고 특정 문제를 강조 표시하면 사람들이 질문에 더 잘 반응 할 수 있습니다. –

+2

형식을 정렬하고 코드 양을 줄이십시오. 코드가 실제로 필요한 것은 특정 변환기에만 문제가있는 것입니까? – GenericTypeTea

+2

"변환기가 내게 이걸주고 어디에 문제가 있는지 응용 프로그램을 호출하는 곳입니다 .Current.Dispather.BeginInvoke." 그리고 당신이 가진 문제는 무엇입니까? 이것은 (a) 코드의 관련 부분 만 보여 주었고 (b) 실제로 문제가 무엇인지 말하면 훨씬 쉽게 대답 할 수 있습니다. –

답변

1

Function.
별도의 기능으로 이동하고 적절한 주소로 전화를 걸거나 받아야합니다.

VB.Net에서 할 수없는 많은 것들이 있습니다 (특히 lamdas 및 익명 메소드와 관련이 있습니다).

이 아닌 많은 언어 요소가 있습니다. 보조 노트에

+0

도움 주셔서 감사합니다. 아마 나는 그것을 다른 방식으로 할 필요가있을 것이다. 내보기에 대한 목록 상자가 있고 MVVM 사용하고 그 목적을 패배 이후 코드에서 아무것도 원하지 않지만 목록 상자에서 selectionChanged 취소 할 수 있어야합니다 그들은 거기에 적용된 havent havent 경우. VB.net에서는 다른 언어를 허용하지 않으므로이 작업을 수행해야합니다. – spafa9

+0

@ spafa9 : 다른 회사를 필요로하는 것 같습니다.

0

이 시도 ...

Public Property CurrentPersonCancellable() As Person 
    Get 
     Debug.WriteLine("Getting CurrentPersonCancellable.") 
     Return _CurrentPersonCancellable 
    End Get 
    Set 
     ' Store the current value so that we can ' 
     ' change it back if needed.' 
     Dim origValue = _CurrentPersonCancellable 

     ' If the value hasnt changed, dont do anything.' 
     If value = _CurrentPersonCancellable Then 
      Return 
     End If 

     ' Note that we actually change the value for now.' 
     ' This is necessary because WPF seems to query the ' 
     ' value after the change. The combo box' 
     ' likes to know that the value did change.' 
     _CurrentPersonCancellable = value 

     If MessageBox.Show("Allow change of selected item?", "Continue", MessageBoxButton.YesNo) <> MessageBoxResult.Yes Then 
      Debug.WriteLine("Selection Cancelled.") 

      ' change the value back, but do so after the ' 
      ' UI has finished its current context operation.' 
      Application.Current.Dispatcher.BeginInvoke(New Action(of Person)(addressof dispatcherCallerHelper), _ 
                 DispatcherPriority.ContextIdle, _ 
                 new Object() {origValue}) 

      ' Exit early. ' 
      Return 
     End If 

     ' Normal path. Selection applied. ' 
     ' Raise PropertyChanged on the field.' 
     Debug.WriteLine("Selection applied.") 
     OnPropertyChanged("CurrentPersonCancellable") 
    End Set 
End Property 

private sub dispatcherCallerHelper(origValue as Person) 
    Debug.WriteLine("Dispatcher BeginInvoke " & "Setting CurrentPersonCancellable.") 

    ' Do this against the underlying value so ' 
    ' that we dont invoke the cancellation question again.' 
    _CurrentPersonCancellable = origValue 
    OnPropertyChanged("CurrentPersonCancellable") 
end sub 

, 당신의 OnPropertyChanged를 기능을 위해, 당신은 정적 반사를 사용하는 것이 좋습니다 :

http://www.codeproject.com/Articles/36262/Getting-Fun-with-NET-Static-Reflection.aspx

건배!

+0

감사합니다! 나는 한번 살펴 보겠다. – spafa9