0

私は UWP アプリケーションを作成しています。私の要件は、タスクバーのサイズをプログラムで取得することです (このアプリケーションは、異なる解像度のタブレットで実行されます)。スタックオーバーフローに関する多くの回答(実際にはタスクバーの非表示/表示に関連していた)をたどった後、私はこれにたどり着きました:

タスクバーの位置とサイズを取得するにはどうすればよいですか?

しかし、これは UWP アプリの場合には実行できません。TaskBar の高さを取得する他の方法はありますか。

:私のアプリケーションの場合、タスクバーは常に表示されています。非表示にするつもりはありません

ありがとう!!

4

2 に答える 2

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!!

于 2015-11-26T09:05:28.187 に答える
1

UWP アプリがサポートされているすべてのプラットフォームにデスクトップやタスク バーがあるわけではありません (また、デスクトップは、カメラ、マイク、動き、位置センサーなどのデバイス機能の 1 つとしてカウントされません)。

デスクトップにアクセスする必要がある場合は、デスクトップ アプリを作成する必要があります。

于 2015-11-24T16:37:19.070 に答える