나는 특정 문자열에 값이 있는지 여부에 따라 기본적으로 표시하거나 숨기고 싶은 버튼이 있습니다. 나는 변환기로 databindings를 사용하려고 했으므로 코드에서 단추를 만들지 만 값이 변경된 후에는 바인딩에서 변환기를 가져올 수 없습니다. 이 올바르게 또는하지 않을 경우 잘 모르겠습니다 ... 여기는 단추 및 바인딩 및 변환기 만들기위한 무엇입니까. "sFileLocation"은 내 클래스 "QuestionsFile"안에있는 문자열입니다. 이것은 초기화를 위해 작동하지만 문자열 값이 변경되면이 바인딩은 변경 사항을 인식하지 못하고 변환기와 모든 것을 실행하지 않습니다 ... 어떤 도움을 주셔서 감사합니다.WPF Databinding Converter .NET
Dim btn2 As New Button
Dim b2 As New Binding("sFileLocation")
b2.Mode = BindingMode.TwoWay
b2.Source = DirectCast(q, QuestionListClass.QuestionsFile)
b2.Converter = New ViewButtonConverter
b2.ConverterParameter = b2.Source
btn2.SetBinding(Button.VisibilityProperty, b2)
<ValueConversion(GetType(String), GetType(Visibility))> _
Public Class ViewButtonConverter
Implements IValueConverter
Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
Dim result As Visibility = Visibility.Collapsed
If parameter IsNot Nothing Then
If parameter.GetType Is GetType(String) Then
If DirectCast(parameter, String) <> "" Then
result = Visibility.Visible
Else
result = Visibility.Collapsed
End If
End If
End If
Return result
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
Return Nothing
End Function
End Class
'this how my class is set up now, its enormous or else id post all of it..
Public Class QuestionListClass
Public Class QuestionList
Inherits ObservableCollection(Of QuestionType)
End Class
End Class
내가 이해하지 못하는 것은 Button.Content에 속성을 바인딩하면 바인딩이 제대로 작동한다는 것입니다. 따라서 속성이 변경되면 올바르게 업데이트되므로 버튼 내용이 적절하게 변경됩니다.
(호출되는 컨버터 잘못되어 가고 있지만,이 정렬 된 후에는, 당신은 [가시성 열거]로부터 값을 돌려 줄 필요가 있는지 확인 http://msdn.microsoft.com/en-us/library하지 않음 /system.windows.visibility.aspx) 문자열 대신 컨트롤의 Visibility 속성을 바인딩하는 경우. –