1

I am implementing a user control which has a grid which again contains a grid (lets say sampleGridItem) with button, textblock etc. sampleGridItem is populated with a list in code behind. My goal is when a button is pressed it will disable the button till the operation of button completes. Than it will again enable same button. But the problem is when the button is disabled it changes the focus to the next grid item. Is there anyway to avoid this focus change situation?

This is the sample code,

<Grid>
    <Grid x:Name="sampleGridItem>
        <Button x:Name="SampleButton"
                click="buttonClickEvent" />
        <Textblock x:Name="SampleTextBlock"/>
    </Grid>
</Grid>

In code behind

private void buttonClickEvent(object sender, RoutedEventArgs e)
{
    SampleButton.IsEnabled = false;
    // Do something    
    SampleButton.IsEnabled = true;
}

Update: I think I need to elaborate more, The sampleGridItem is produced from an observable collection, so there are multiple grid items generated in a grid. When clicking the button in one grid item it at first disable the button as a result it changes the focus in next grid item. I am trying to stop this focus change.

2
  • 1
    If you're worried about "re-entrancy"; toggle a "busy" flag. If "busy", skip over "something". Part of that might include setting e.Handled to "True". Commented Sep 19, 2024 at 21:15
  • You need to show the detailed code for reproducing the issue. Commented Sep 24, 2024 at 7:57

1 Answer 1

1

Try setting TextBox's IsTabStop to false:

private void Button_Click(object sender, RoutedEventArgs e)
{
    SampleTextBox.IsTabStop = false;
    SampleButton.IsEnabled = false;
    // Do something...
    SampleButton.IsEnabled = true;
    SampleTextBox.IsTabStop = true;
}
Sign up to request clarification or add additional context in comments.

1 Comment

hello unfortunately it still did not work. I have tried to elaborate more in my question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.