1

作業中のWPFアプリケーションがあり、フォームは画像を使用して作成されています...フォームのサイズ変更で問題が発生しました。

問題は、上部の個々の行の背景について、高さを固定サイズに保ちながら、幅をウィンドウに合わせてサイズ変更できるようにする必要があることです...ただし、高さまたは最大高さの値を入力しようとすると、そのようなものは、画像コントロールがウィンドウに完全にフィットしなくなります。

私はWPFに慣れていないので、これはまったく間違った方法で行っている可能性があります。誰かがこれを行うためのより良い方法を持っている場合は、私に知らせてください。

これは私がこれまで使用しているXAMLであり、問​​題はTitleBarImageにあります。

<Window x:Class="App.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Application" Height="{Binding SystemParameters.PrimaryScreenHeight}" Width="{Binding SystemParameters.PrimaryScreenWidth}" AllowsTransparency="True" WindowStyle="None" MinWidth="1024" MinHeight="749" WindowStartupLocation="CenterScreen">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Image x:Name="TitleBarImage" Grid.Row="0" Grid.ColumnSpan="3" HorizontalAlignment="Stretch" VerticalAlignment="Top" Source="skin/title-bar.png" MouseLeftButtonDown="TitleBarImage_MouseLeftButtonDown" MouseDown="TitleBarImage_MouseDoubleClick"/>
        <Image HorizontalAlignment="Right" Grid.Row="0" Grid.Column="2" Height="23" Margin="0,17,74,0" VerticalAlignment="Top" Width="34" Source="skin/min-button.png" MouseLeftButtonUp="MinImage_MouseLeftButtonUp"/>
        <Image HorizontalAlignment="Right" Grid.Row="0" Grid.Column="2" Height="23" Margin="0,17,40,0" VerticalAlignment="Top" Width="34" Source="skin/max-button.png" MouseLeftButtonUp="MaxImage_MouseLeftButtonUp"/>
        <Image HorizontalAlignment="Right" Grid.Row="0" Grid.Column="2" Height="23" Margin="0,17,7,0" VerticalAlignment="Top" Width="33" Source="skin/close-button.png" MouseLeftButtonUp="Image_MouseLeftButtonUp_1" RenderTransformOrigin="21.121,-4.522"/>
    </Grid>
</Window>
4

1 に答える 1

2

画像のStretchプロパティをFillに設定する必要があります。そうしないと、元のアスペクト比が維持され、領域に適切にフィットしません。

<Image ... Stretch="Fill"/>
于 2013-01-27T11:03:14.157 に答える