2017-05-29 41 views
0

WPFの好奇心に遭遇しましたが、オンラインで検索することで解決できなかった自分自身を説明できませんでした。だから私の間違いを理解するためのヒントをあなたの一人が私に与えることができれば幸いです。画面サイズとwpfウィンドウサイズの値が異なります

問題:wpf-windowのサイズが画面解像度よりも16単位大きいようです。 16ピクセル/単位は、寸法(ウィンドウ幅、ウィンドウ高さ)および画面解像度から独立しています。 問題は、以下の出願に示されている:

XAML:

<Window x:Class="WpfApplication1.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="MainWindow" Height="250" Width="350"> 
    <DockPanel Margin="10,10,0,0"> 
     <DockPanel Width="152" DockPanel.Dock="Top" VerticalAlignment="Top" HorizontalAlignment="Left"> 
      <TextBlock x:Name="displayHeight" HorizontalAlignment="Left" Margin="0,5,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="60"/> 
      <Label Content="Displayheight" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30"/> 

     </DockPanel> 

     <DockPanel Width="148" DockPanel.Dock="Top" VerticalAlignment="Top" HorizontalAlignment="Left"> 
      <TextBlock x:Name="displayWidth" HorizontalAlignment="Left" Margin="0,5,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="60"/> 
      <Label Content="Displaywidth" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30"/> 

     </DockPanel> 
     <DockPanel Width="162" DockPanel.Dock="Top" VerticalAlignment="Top" HorizontalAlignment="Left"> 
      <TextBlock HorizontalAlignment="Left" Margin="0,5,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Text="{Binding ActualHeight, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" Width="60"/> 
      <Label Content="Windowheight" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" Width="92"/> 

     </DockPanel> 
     <DockPanel Width="153" DockPanel.Dock="Top" VerticalAlignment="Top" HorizontalAlignment="Left"> 
      <TextBlock HorizontalAlignment="Left" Margin="0,5,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Text="{Binding ActualWidth, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" Width="60"/> 
      <Label Content="Windowwidth" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30"/> 

     </DockPanel> 

    </DockPanel> 
</Window> 

C番号:

using System; 
using System.Collections.Generic; 
using System.Diagnostics; 
using System.Windows; 
using System.Windows.Forms; 
using System.Drawing; 

namespace WpfApplication1 
{ 
    public partial class MainWindow : Window 
    { 
     public MainWindow() 
     { 
      InitializeComponent(); 

      IntPtr ownerHandle = Process.GetCurrentProcess().MainWindowHandle; 
      WpfScreen currentScreen = WpfScreen.GetScreenFrom(ownerHandle); 
      Rect workingArea = currentScreen.WorkingArea; 

      this.displayHeight.Text = workingArea.Height.ToString(); 
      this.displayWidth.Text = workingArea.Width.ToString(); 
     } 
    } 

    public class WpfScreen 
    { 
     public static WpfScreen GetScreenFrom(IntPtr windowIntPTR) 
     { 
      Screen screen = System.Windows.Forms.Screen.FromHandle(windowIntPTR); 
      WpfScreen wpfScreen = new WpfScreen(screen); 
      return wpfScreen; 
     } 

     private readonly Screen screen; 

     internal WpfScreen(System.Windows.Forms.Screen screen) 
     { 
      this.screen = screen; 
     } 

     public Rect WorkingArea 
     { 
      get { return this.GetRect(this.screen.WorkingArea); } 
     } 

     private Rect GetRect(Rectangle value) 
     { 
      return new Rect 
      { 
       X = value.X, 
       Y = value.Y, 
       Width = value.Width, 
       Height = value.Height 
      }; 
     } 
    } 
} 

基本的コードは、Excelの高さ/幅の最大-値を設定するために必要とされます - ディスプレイの利用可能な作業領域に追加します。上記のアプリケーションは、問題を説明するための単純な例です。

私の場合、16ピクセルは普遍的に有効であり、ハード/ソフトウェアから独立していることだけを知っていればよいでしょう。それにもかかわらず、この行動の理由は何か説明を得ることは素晴らしいことです。

挨拶と事前にTHX、

スヴェン

答えて

0

なぜ

WPFを使用WindowState="Maximized"

参照:How can I make a WPF window maximized on the screen with the mouse cursor?

+0

平均WPFウィンドウがあるため、デフォルトではSizeToContentをする必要がありますスクリーンワーキングエリアよりもはるかに小さい。一つの大きな問題は、640×480の解像度しか持たないプロジェクターの使用です。 –

+0

申し訳ありませんが、おそらくこれはあなたを助けます:https://msdn.microsoft.com/en-us/library/system.windows.systemparameters(v=vs.110).aspx(例:BorderWidth) – incureforce

+0

心配はいりません。私はこれを明確にすべきでした:デフォルトのWPFサイズはSizeToContent、Min = 640 * 480、Max = workingareaでなければなりません。私はちょうどSystemparametersを見てみましたが、残念ながら正しい値を見つけられませんでした。私の場合、BorderWidthは5.0です(そして、それが何を表しているかはわかりませんでした...) –

関連する問題