2

プログラムを中央に配置しようとしているので、ページを変更しても中央に配置されたままになります。現状では中央揃えになっていますが、ページを変更すると中央揃えではなくなります。

次のコードを使用してみましたが、ページでは機能しません。ありがとう!

this.Left = (SystemParameters.PrimaryScreenWidth / 2) - (this.ActualWidth / 2);

this.Top = (SystemParameters.PrimaryScreenHeight / 2) - (this.ActualHeight / 2);
4

1 に答える 1

0

Page についてはよくわかりませんが、Window には Property WindowStartupLocation があります。このプロパティは、3 つの列挙値 1)CenterScreen 、2) Manual 、3) CenterOwner のいずれかを持つことができます。次に、プロパティを次のように設定します

<myWindow:CustomPage x:Class="WpfApplication4.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:myWindow="clr-namespace:WpfApplication4"
    Title="MainWindow" Height="800" Width="800" WindowStartupLocation="CenterScreen">
<Grid>

</Grid>

これが役立つことを願っています。

于 2012-11-15T05:30:21.437 に答える