locked
Slider resizing not correctly after changing visual state

    Question

  • I am faced a problem with sizing of slider in WinRT project. I have simple default slider in my xaml, like this:

     <Slider x:Name="slider1" 
                HorizontalAlignment="Stretch"
                VerticalAlignment="Top"
                BorderBrush="White" 
                BorderThickness="5"/>

    his slider have width along all page and when this page changing its size, slider must change his size too. But here is the problem. If i am set slider's value to maximum point and drag app window to portrait state, size of slider doesn't changing on the view. It become to actual size only after manipulation. I have already tried to monitor data, when fires up SizeChanged event and slider takes correct NewSize, but doesn't changing its view. On the screen below you can see what i talking about. Slider's body goes out of the window in portrait state(or any other).

    So is it bug of defaul control and how i can workaround this issue?

    Wednesday, December 10, 2014 4:58 PM

Answers

  • Hi RenDishen,

    Thank you for reporting this issue. I can reproduce this too. For a quick work around, I think you can use the following code snippet. I have tested and it worked.

    # handle the SizeChanged event in Slider control.

    private async void slider1_SizeChanged(object sender, SizeChangedEventArgs e)
            {
                double val = slider1.Value;
                slider1.Value = 0;
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,() => slider1.Value = val );
            }
    

    Please feel free to let me know if you have any concerns.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    Tuesday, December 16, 2014 5:30 AM
    Moderator

All replies

  • I can reproduce the problem. It's very odd and must be a bug.
    Someone else had also encountered it, but there was no resolution:
    Thursday, December 11, 2014 8:34 AM
  • Yes, i saw this topic in stack, but workaround proposed there is pretty ugly. But i didn't find anything other.
    Thursday, December 11, 2014 8:58 AM
  • Hi RenDishen,

    Thank you for reporting this issue. I can reproduce this too. For a quick work around, I think you can use the following code snippet. I have tested and it worked.

    # handle the SizeChanged event in Slider control.

    private async void slider1_SizeChanged(object sender, SizeChangedEventArgs e)
            {
                double val = slider1.Value;
                slider1.Value = 0;
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,() => slider1.Value = val );
            }
    

    Please feel free to let me know if you have any concerns.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    Tuesday, December 16, 2014 5:30 AM
    Moderator