Kofoed

I'm struggling with the IsFocused property for different controls because it seems to behave differently. Certain input controls like TextBoxes have the IsFocused property set to TRUE when focus is received via the keyboard OR mouse.

TextBlocks, labels, checkboxes and other controls only have the IsFocused property set to true when focus is received via the keyboard.

Is there a reason for this, or a way I can get around this

I'm basically trying to set a visual style for all controls when they receive focus ... via the mouse OR keyboard.



Re: Windows Presentation Foundation (WPF) What is WITH the focus property??

LesterLobo - MSFT

in textbox/buttons the mouse click event is handled and hence the focus property is set. This is not so in the case of textblock.labels..

Clicking on the textblock sets the focus property on the parent... you could call tbl.Focus() programmatically to set the focus property

<FlowDocumentPageViewer >
<FlowDocument>
<Paragraph>This is some text:

<Button>dddd</Button>.

<TextBlock Foreground="red" Background="blue" Name="tbl" Focusable="true" >ssss</TextBlock>

</Paragraph>
</FlowDocument>
</FlowDocumentPageViewer>





Re: Windows Presentation Foundation (WPF) What is WITH the focus property??

Kofoed

When you say "set it programmatically", do you mean from the code behind, or from XAML as you indicate in your sample code Because I've tried setting the Focusable=True attribute, but the behavior is stil the same.





Re: Windows Presentation Foundation (WPF) What is WITH the focus property??

LesterLobo - MSFT

you need to set focus through code...the xaml property just indiccates that the control can be focused.





Re: Windows Presentation Foundation (WPF) What is WITH the focus property??

Kofoed

I tried setting the focus manually from the MouseLeftButtonDown event ... but no dice. The FocusRectangle still only appears through keyboard input.

void Eclp_LinkLabel_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)

{

this.Focus();

}