1

Windowsアプリケーションをwpfアプリケーションに変換しようとしていますが、すべて問題ありませんが、この時点で、wpfのコードで次の宣言が機能しないように変換することになりました。

これらはWindows宣言です。

Dim screenwidth As String = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width

Dim screenheight As String = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height

私はこれらの宣言と同等のクラスプロパティを見つけるためにグーグルで検索しました、そして私はいくつかのものを手に入れました、しかしそれらは存在していますが、私がそれらを使おうとしている時点では機能していません

" PointToScreen(New Point(0,0)) "は次のとおりです。

コードでこれらを使用する場合:

Dim screenwidth As String = System.Windows.SystemParameters.VirtualScreenWidth Dim screenheight As String = System.Windows.SystemParameters.VirtualScreenHeight'(OR)

Dim screenwidth As String = System.Windows.SystemParameters.PrimaryScreenWidth Dim screenheight As String = System.Windows.SystemParameters.PrimaryScreenHeight

       With MyPanel
            .PointToScreen(New Point(SystemParameters.VirtualScreenWidth, 0)) ' Getting Exception in this line               
            .Height = (80 / 1080) * screenheight
            .Width = screenwidth                
            .Background = New SolidColorBrush(Colors.Transparent)
        End With

「ビジュアルがPresentationSourceに接続されていません」という無効な操作例外として例外が発生しています。

私はすでにこの投稿http://social.msdn.microsoft.com/Forums/en/wpf/thread/f3c982a1-ca16-4821-bf08-f6dd8ff8d829 を試しましたが、PointToScreenのみを使用して試したいと思います。

どうすればこれを解決できますか???? 私を助けてください

4

2 に答える 2

1

こんにちは、これを試して、画面の幅と高さを取得してください。

double width=System.Windows.SystemParameters.PrimaryScreenWidth;
double height = System.Windows.SystemParameters.PrimaryScreenHeight;

例外は、レンダリングされる前にMypanelをポイントしているためです。このようにしてください

if (MyPanel.IsVisible)
        { 
            MyPanel
            .PointToScreen(New Point(SystemParameters.PrimaryScreenWidth, 0)) ' Getting Exception in this line               
            .Height = (80 / 1080) * screenheight
            .Width = screenwidth                
            .Background = New SolidColorBrush(Colors.Transparent)
        }

これがお役に立てば幸いです。

于 2012-07-30T05:40:36.337 に答える
0

これはどう:

Screen.PrimaryScreen.WorkingArea.Height

Screen.PrimaryScreen.WorkingArea.Width

DPI設定を検討する場合は、これを使用します(_windowToControlはアプリケーションのウィンドウです)。

    public double ScreenPixelHeight
    {
        get
        {
            PresentationSource source = PresentationSource.FromVisual(_windowToControl);
            if (source != null)
                return Screen.PrimaryScreen.WorkingArea.Height * source.CompositionTarget.TransformFromDevice.M11;
            else
                return 0;
        }
    }
    public double ScreenPixelWidth
    {
        get
        {
            PresentationSource source = PresentationSource.FromVisual(_windowToControl);
            if (source != null)
                return Screen.PrimaryScreen.WorkingArea.Width * source.CompositionTarget.TransformFromDevice.M11;
            else
                return 0;
        }
    }
于 2012-07-30T12:30:33.037 に答える