C#中的屏幕分辨率 - wpf

时间:2016-01-18 12:45:51

标签: c#-4.0

我的程序要求在所有不同的分辨率上适应屏幕。 我尝试过在XAML中使用代码,但没有运气:(

标题="结构"图标="图像/ Logo.png"背景=" {StaticResource SAFMThemeWindowBackGroundColour}" EnableDWMDropShadow ="真" WindowStartupLocation ="中心屏幕"的WindowState ="最大化"装载=" Window_Loaded"闭=" WINDOW_CLOSING" =了minHeight" 725" MinWidth =" 1366"                       宽度=" {Binding SystemParameters.PrimaryScreenWidth}"高度=" {Binding SystemParameters.PrimaryScreenHeight}">

请帮助我..我在WPF中不够好。

1 个答案:

答案 0 :(得分:0)

我发现此代码可以解决问题:

   public MainForm()
    {
        InitializeComponent();
        this.Loaded += SwapResol;
    }


    private void SwapResol(object sender, EventArgs e)
    {
        double width = System.Windows.SystemParameters.PrimaryScreenWidth;
        if (width == 1920)
        {
            //Code Here
        }
        else if (width == 1280)
        {
            //Code Here  
        }
        else if (width == 1600)
        {
            //Code Here
        }

}

相关问题