如何将窗口的高度调整到屏幕顶部?

时间:2016-03-14 17:50:06

标签: c# wpf

我在WPF中有一个窗口,我需要说明适合屏幕的顶部,宽度只需要800像素。 我有这个但没有工作:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output encoding="iso-8859-1"/>
<xsl:output method="xml" indent="yes" omit-xml-declaration="no"/>

    <xsl:key name="level0" match="/KBBCONNECTJOB/OGOODS/Row" use="ORDERNO" />  <!-- group -->
    <xsl:key name="level1" match="/KBBCONNECTJOB/OGOODS/Row" use="concat(ORDERNO, '|', WHAT)" />  <!-- group by WHAT -->
    <xsl:key name="level2" match="/KBBCONNECTJOB/OGOODS/Row" use="concat(ORDERNO, '|', WHAT, '|', SUPP)" />   <!-- group by WHAT and SUPP -->
    <xsl:key name="level3" match="/KBBCONNECTJOB/OGOODS/Row" use="concat(ORDERNO, '|', WHAT, '|', SUPP, '|', POS)" />   <!-- group by WHAT and SUPP and POS to get the lines -->
    <xsl:key name="level4" match="/KBBCONNECTJOB/OGOODS/Row" use="concat(ORDERNO, '|', WHAT, '|', SUPP, '|', POS, '|', NAME)" /> 


    <xsl:template match="/KBBCONNECTJOB">
        <xsl:for-each select="/KBBCONNECTJOB/OGOODS/Row[count(. | key('level0', ORDERNO)[1]) = 1]">
            <order>
                <xsl:attribute name="display">
                    <xsl:value-of select="ORDERNO"/>
                </xsl:attribute>

                <xsl:for-each select="/KBBCONNECTJOB/OGOODS/Row[count(. | key('level1', concat(ORDERNO, '|', WHAT))[1]) = 1]">  <!-- get the WHAT groups -->
                    <xsl:sort select="WHAT" />                      

                    <productgroup>
                        <xsl:for-each select="key('level3', concat(ORDERNO, '|', WHAT, '|', SUPP, '|', POS))">
                            <xsl:variable name="lookup_what" select="WHAT"/>
                            <xsl:attribute name="display">
                <!--                <xsl:value-of select="document('./Lookups/lookup_specialsmap.xml')/data/kbbproducttab[@what=$lookup_what]/type"/>  -->
                            </xsl:attribute>

                            <supplier>
                                <xsl:for-each select="key('level4', concat(ORDERNO, '|', WHAT, '|', SUPP, '|', POS, '|', NAME))">
                                    <xsl:variable name="lookup_supp" select="SUPP"/>
                                    <xsl:attribute name="display">
    <!--                                    <xsl:value-of select="document('./Lookups/lookup_suppliers.xml')/data/kbbsupplier[@code=$lookup_supp]/k8suppliercode"/>   -->
                                    </xsl:attribute>

                                    <product>
                                        <xsl:for-each select="key('level4', concat(ORDERNO, '|', WHAT, '|', SUPP, '|', POS, '|', NAME))">

                                            <xsl:attribute name="display">
                                                <xsl:value-of select="NAME"/>
                                            </xsl:attribute>
                                            <xsl:attribute name="what">
                                                <xsl:value-of select="WHAT"/>
                                            </xsl:attribute>
                                            <xsl:attribute name="pos">
                                                <xsl:value-of select="POS"/>
                                            </xsl:attribute>
                                            <xsl:attribute name="ordercat">
                                                <xsl:text>D</xsl:text>
                                            </xsl:attribute>
                                        </xsl:for-each>
                                    </product>
                                </xsl:for-each>
                            </supplier>
                        </xsl:for-each>
                    </productgroup>
                </xsl:for-each>
            </order>    
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

我也试过这个,但它给出了错误:

Title="Title" Height="Auto" Width="800" WindowStartupLocation="CenterScreen" ResizeMode="CanResize" Icon="/img/icon.ico" Loaded="Window_Loaded">

有谁知道怎么做?

2 个答案:

答案 0 :(得分:1)

从您的Xaml代码中删除WindowStartupLocation="CenterScreen"并插入Left="0" Top="0"。您可以根据需要增加Left值。

<强>更新

误解,我没有得到窗口应采取全屏高度(任务栏除外)。

最终的解决方案是:

<Window ... 
        WindowStartupLocation="CenterScreen"
        Height="{Binding Source={x:Static SystemParameters.WorkArea}, Path=Height}"
        Width="800" >

答案 1 :(得分:1)

您可以将窗口高度设置为屏幕高度,然后尝试在Window_Loaded事件中设置窗口的位置,如下所示:

private void Window_Loaded(object sender, RoutedEventArgs e)
{
    var CurrentWindow = (sender as Window);
    CurrentWindow.Height = SystemParameters.PrimaryScreenHeight;
    CurrentWindow.Top = 0;
    CurrentWindow.Left = SystemParameters.PrimaryScreenWidth / 2 - CurrentWindow.Width / 2;
    CurrentWindow.MaxHeight = SystemParameters.WorkArea.Bottom;

}