아무도 내가 이것을 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
작업을 수행하도록 요청하지 않고 특정 문제를 강조 표시하면 사람들이 질문에 더 잘 반응 할 수 있습니다. –
형식을 정렬하고 코드 양을 줄이십시오. 코드가 실제로 필요한 것은 특정 변환기에만 문제가있는 것입니까? – GenericTypeTea
"변환기가 내게 이걸주고 어디에 문제가 있는지 응용 프로그램을 호출하는 곳입니다 .Current.Dispather.BeginInvoke." 그리고 당신이 가진 문제는 무엇입니까? 이것은 (a) 코드의 관련 부분 만 보여 주었고 (b) 실제로 문제가 무엇인지 말하면 훨씬 쉽게 대답 할 수 있습니다. –