1

I am making an UWP application.My requirement is to get the size of the TaskBar programatically (This application will run on Tablets of different resolution). After following many answers on stackoverflow(which were actually more relevant to hiding/showing the taskbar), I came through this:

How do I get the taskbar's position and size?

But this can't be done in case of UWP apps.Is there any other way to get the Height of the TaskBar.

Please Note : The TaskBar is always visible in case of my application.I don't intend to hide it

Thanks!!

Community
  • 1
  • 1
Saurabh Rai
  • 361
  • 2
  • 18

2 Answers2

3

Well!! So after a lot of searching on internet, seeing similar answers on stackoverflow and suggestions, It seems that calculating the TaskBar height in UWP application is not so straight or simple task. However for my situation I ended up with this work around which works fine. But I will continue to find a proper approach. Assuming my screen resolution is 1600x900 ,So here is what I did:

    private void GetScreenDimension()
    {

        //To get Screen Measurements e.g. height, width, X,Y...
        ApplicationView view = ApplicationView.GetForCurrentView();
        //Getting the Window Title Bar height(In my case I get :Top=32,Bottom=860)
        double titleBarHeight = view.VisibleBounds.Top;
        //Getting the TaskBar Height
        double taskBarHeight = view.VisibleBounds.Top + (view.VisibleBounds.Top / 4);
        //Getting the workable Height of the screen ( excluding Task Bar Height)
        double availableheight = GridTimelineContent.ActualHeight - taskBarHeight;
        double availablewidth = GridTimelineContent.ActualWidth;

        if (_viewModel != null)
        {
            _viewModel.AvailableHeight = availableheight;
            _viewModel.AvailableWidth = availablewidth;
            //Getting the actual Physical height (i.e including TitleBar Height and Task Bar Height, gives 900 in my case which is what I wanted)                              
            _viewModel.ActualScreenHeight = view.VisibleBounds.Height + titleBarHeight + taskBarHeight;

            _viewModel.PageWidth = (this as Page).ActualWidth;

        }
    }

Please Note:

1) When I run the application with TaskBar Locked(visible), I get view.VisibleBounds.Height as 828.

2) When I run the application with TaskBar AutoHidden(Invisible), I get view.VisibleBounds.Height as 868.

Which gave me an idea that 900-868=32 could be Tittle Bar Height, and as I jumped from 828 to 868 after hiding the Task Bar means 868-828=40 could be the Task Bar Height.

Conclusion:

Title Bar Height = view.VisibleBounds.Top (Which is 32)

Task Bar Height = view.VisibleBounds.Top (Which is 32) + (view.VisibleBounds.Top / 4)(Which is 8);(32+8 = Total 40)

Remainning Height = view.VisibleBounds.Height (Which is 828)

If I combine the above three, I get 900 (Required Height) using this line of code:

_viewModel.ActualScreenHeight = view.VisibleBounds.Height + titleBarHeight + taskBarHeight;

I hope it's useful for others too. Thanks!!

Saurabh Rai
  • 361
  • 2
  • 18
0

It can't be done simply because not every platform where UWP apps are supported even has a Desktop or TaskBar (and the desktop doesn't count as one of the device capabilities such as camera, microphone, movement or location sensors)!

If you need to access the Desktop you will have to create a desktop app.

Dirk Vollmar
  • 172,527
  • 53
  • 255
  • 316
  • Yeah I agree to your point. But what I am trying to ask is that Tablets which have Tablet Mode and Desktop Mode(New Windows 10 devices), how do i get the height of Taskbar in these tablets? You may assume that this application will only be used on say Surface or HP stream Tablets(Sorry but just Assume). I just want to know a way to find the height of the Task Bar. – Saurabh Rai Nov 25 '15 at 05:31
  • @SaurabhRai: I'm sorry to be not more helpful here. Maybe you can explain your actual requirements a bit more. Do you simply want to run your app full-screen? – Dirk Vollmar Nov 25 '15 at 09:29
  • Thanks for your support. I found a work around for my situation and mentioning the same in the answer. But if you still have a better way let me know. – Saurabh Rai Nov 26 '15 at 07:35