Question

I'm using the following code to bind the RichTextBlock.Visibility property to another control's FocusState property.

 <RichTextBlock FontFamily="Segoe UI" FontSize="22" FontWeight="Light" 
                               Foreground="{StaticResource SwiftLightTextBrush}" 
                               Visibility="{Binding ElementName=ProfessionalHeadlineInput, Path=FocusState, Converter={StaticResource FocusStateToVisibilityConverter}}" >

The implentation of FocusStateToVisibilityConverter.Convert is the following:

public object Convert(object value, Type targetType, object parameter, string language)
{
    var focusState = (FocusState)value;

    return focusState == FocusState.Keyboard || focusState == FocusState.Pointer || focusState == FocusState.Programmatic ? Visibility.Visible : Visibility.Collapsed;
}

It may be a novice question, but why the binding is not applied when I'm 'focusing' onto a target element (ProfessionalHeadlineInput is a TextBox element) using the mouse or tab navigation?

I've inserted the breakpoint into the Convert method, but it is not called when I'm clicking or 'tabbing' onto the ProfessionalHeadlineInput TextBox.

NB The important part - my project is a Windows 8 Metro Style Application.

Was it helpful?

Solution 2

I've got an answer from Matt Small on Microsoft forum:

OK - this is actually a bug with FocusState - it's not updating the value. I'm filing a bug in our database. Thank you for brining this up.

OTHER TIPS

Make sure FocusState is DP, make sure it actually chages The only reason I see here - FocusState may not change, everything else looks fine. Also, try to explicitly set Mode=OneWay and UpdateSourceTrigger=PropertyChanged

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top