开发者

Why does making a stackpanel visible after clicking a radiobutton make ScrollToVerticalOffset stop working?

I am trying to make it so that there are three radiobuttons. When the user clicks on the first one, a textbox and some other controls appear underneath (a stackpanel goes from collapsed to visible). I want the phone to automatically scroll so that the textbox is centered on the screen so the user doesn't have to scroll down to see it.

Here is the code for when the user clicks on the radio button:

    private void checkbox1_Checked(object sender, RoutedEventArgs e)
    {
        checkbox1_options.Visibility = Visibility.Visible;
        addEntryScrollViewer.ScrollToVerticalOffset(checkbox1.ActualHeight + 150);
    }

The problem I am having is that the first time I click on the radiobutton it doesn't scroll at all. If I click on a different radiobutton and then click on the first one again (i.e. everything is already visible when I click the r开发者_运维技巧adiobutton) it works perfectly fine.

Anyone got some idea on what this could be?


You need to check the state of the button. I can only assume that initially you have a specific state set (e.g. it is already checked) so the event handler is not fired. Also, set event breakpoints to make sure that the code is actually used when testing for something like this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜