1

すべてのウィンドウが同じように見えるように、ボーダーレス ウィンドウ テンプレートを作成しました。テンプレート コードは次のようになります。

public abstract class WindowBase : Window
{
    static WindowBase()
    {
        DefaultStyleKeyProperty.OverrideMetadata(typeof(WindowBase), new FrameworkPropertyMetadata(typeof(WindowBase)));
    }
}

そして、私は次のようなスタイルを持っています:

    <Style TargetType="{x:Type WindowBase}">
        <!--<Setter Property="Topmost" Value="True" />-->
        <Setter Property="WindowStyle" Value="None" />
        <Setter Property="Background" Value="White"/>
        <Setter Property="ResizeMode" Value="CanResizeWithGrip" />
        <Setter Property="WindowState" Value="Maximized" />
        <Setter Property="AllowsTransparency" Value="True"/>
        <Setter Property="SnapsToDevicePixels" Value="true"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Window}">
                <Border Margin="0" BorderThickness="1">
                    <Grid>
                        <Grid Background="White" Visibility="Visible">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="1.5*"/>
                                <RowDefinition Height="10*"/>
                            </Grid.RowDefinitions>
                            <ContentPresenter Grid.Row="0" Grid.RowSpan="2"/>
                        </Grid>
                        <ContentPresenter />
                        <ResizeGrip Name="ResizeGroup" VerticalAlignment="Bottom" HorizontalAlignment="Right" KeyboardNavigation.IsTabStop="False"/>
                    </Grid>
                </Border>
                <ControlTemplate.Triggers>
                    <MultiTrigger>
                        <MultiTrigger.Conditions>
                            <Condition Property="ResizeMode" Value="CanResizeWithGrip"/>
                            <Condition Property="WindowState" Value="Maximized"/>
                        </MultiTrigger.Conditions>
                        <Setter Property="Visibility" TargetName="ResizeGroup" Value="Collapsed"/>
                    </MultiTrigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

アプリケーションが最大化された状態で実行されると、ウィンドウが画面スペースを超えていることがわかりました。私が 1600 x 900 にいると仮定すると、私の最大作業領域は 1600 x 900 になりますが、アプリケーションは次のようになります。私の場合は「-7」と表示されます。

どこが間違っているのかよくわかりません。誰か助けてくれませんか?

4

2 に答える 2

1

ResizeModeNoResizeではなく に設定しCanResizeWithGripます。これにより、表示されていませんが、サイズの計算に考慮されているように見えるサイズ変更の境界線が削除されます。

<Style TargetType="{x:Type WindowBase}">
    ...
    <Setter Property="ResizeMode" Value="NoResize" /> 
    ...
</Style>
于 2012-10-14T21:58:20.967 に答える