나는 윈도우에 ListBox와 Button을 가지고있다. ListBox에 포커스가있는 경우 Button의 IsEnabled
속성은 True 여야합니다. 여기에 내가 무엇을 시도했다입니다 :스타일 트리거를 사용하여 다른 컨트롤 바꾸기
<Style TargetType="{x:Type ListBox}">
<Setter
Property="Margin"
Value="15,0,15,20"></Setter>
<Style.Triggers>
<Trigger Property="IsFocused" Value="True" />
<Setter TargetName="btnActivate" Property="IsEnabled" Value="True" />
</Style.Triggers>
</Style>
이것은 매우 간단한 것 같지만 나는
btnActivate가 인식되지 않는다는 오류 메시지가 표시됩니다.
올바른 방법은 무엇입니까?
IsEnabled="{Binding ElementName=lstInactive, Path=SelectedIndex, Converter={StaticResource cvtr}}">
이 변환기를 사용 : 다음과 같이
EDIT 1 나는 MoonMoo의 제안 링크를 구현
이 목록 상자가 집중 될 때의 IsEnabled를 설정하기 위해 노력하고 있지만 켜지지 않습니다Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IValueConverter.Convert
Dim IsFocused As Integer = CInt(value)
Return If(IsFocused > -1, True, False)
End Function
목록 상자에 포커스가 없어지면 꺼집니다. 포커스를 얻을 수있는 다른 컨트롤에 바인딩하는 멀티 바인딩을 조사해야 할 수도 있습니다.
편집 2 은 내가 노력 언급한다 : 컨버터와
IsEnabled="{Binding ElementName=lstInactive, Path=IsFocused, Converter={StaticResource cvtr}}">
:
Return CBool(value)
하지만 그
이와 비슷한 내용이 https://stackoverflow.com/questions/14068606/wpf-bind-a-control-visibility-to-the-focused-property-of-another-control에서 응답되었습니다. 대신 IsEnabled 속성에 바인딩 할 수 있습니다. –
@MoonMoo OP에 대한 나의 편집을보세요. – SezMe