Search code examples
c#xamluser-interfacewinui-3winui

Regarding Sliders in Win UI


I had a little query with regards to Win UI and I was hoping someone could help me out with this. I'm new to the framework and I was playing around with sliders. Below is a picture of a slider taken from the Microsoft Documentation. I was wondering if it was possible to hide the value that pops up at the top, 85 in this case, when I drag the slider around, and if so, what property I am supposed to manipulate to do so.

Many thanks for your time, in advance!

Image of Slider from Microsoft Documentation

I tried looking at the documentation and reading through most of the properties they have highlighted, but there did not seem to be anything that matched the description of what I was looking for. I also tried changing certain properties that might have been related to it, but it is possible I may have overlooked it.


Solution

  • That is a Popup that you can't access directly. You need to grab it using the VisualTreeHelper.GetOpenPopupsForXamlRoot() method.

    Let's say your Slider control is named SliderControl.

    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
            this.SliderControl.LayoutUpdated += SliderControl_LayoutUpdated;
        }
    
        private void SliderControl_LayoutUpdated(object? sender, object e)
        {
            if (VisualTreeHelper
                .GetOpenPopupsForXamlRoot(this.SliderControl.XamlRoot)
                .FirstOrDefault() is Popup popup)
            {
                popup.Visibility = Visibility.Collapsed;
            }
        }
    }