【问题标题】:DynamicResource With Static Parameter in C#?C#中带有静态参数的DynamicResource?
【发布时间】:2011-06-13 06:55:00
【问题描述】:

我正在尝试创建一个无边界 wpf 应用程序,我找到了这段代码

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
    x:Class="VSM.Window2"
    x:Name="Window"
    Title="Window2"
    Width="{DynamicResource {x:Static SystemParameters.MaximizedPrimaryScreenWidthKey}}" 
    Height="{DynamicResource {x:Static SystemParameters.MaximizedPrimaryScreenHeightKey}}"
    WindowStartupLocation="CenterScreen" AllowsTransparency="True" WindowStyle="None"
    >

    <Grid x:Name="LayoutRoot">
        <Rectangle Fill="White" />
    </Grid>
</Window>

Width="{DynamicResource {x:Static SystemParameters.MaximizedPrimaryScreenWidthKey}}" 
    Height="{DynamicResource {x:Static SystemParameters.MaximizedPrimaryScreenHeightKey}}"
AllowsTransparency="True" WindowStyle="None"

将使用 wpf 创建无边框的窗口应用程序。 我想创建一个按钮,该按钮将运行此最大化应用程序。 使用此 xaml 代码:

Width="{DynamicResource {x:Static SystemParameters.MaximizedPrimaryScreenWidthKey}}" 
        Height="{DynamicResource {x:Static SystemParameters.MaximizedPrimaryScreenHeightKey}}"

请帮助我使用 dynamicresource bla bla bla 将宽度和高度转换为 c#,这样我就可以通过编程方式完成。

【问题讨论】:

    标签: c# wpf


    【解决方案1】:

    编写代码(在您从 Window 派生的类中):

    this.Width = System.Windows.SystemParameters.MaximizedPrimaryScreenWidth;
    this.Height = System.Windows.SystemParameters.MaximizedPrimaryScreenHeight;
    

    但是 !!! 考虑(取决于您想要实现的目标):

    • 应用程序的当前显示(您必须导入一些 WinAPI 函数)
    • SystemParameters.VirtualScreenWidth 和 SystemParameters.VirtualScreenHeight
    • SystemParameters.FullPrimaryScreenWidth 和 SystemParameters.FullPrimaryScreenHeight

    另请参阅:SystemParameters

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-14
      • 2017-09-08
      • 1970-01-01
      • 1970-01-01
      • 2014-02-14
      • 2023-03-18
      • 2016-01-30
      • 1970-01-01
      相关资源
      最近更新 更多