2016-04-03 8 views
2

ContentDialogのデフォルトの動作は、PCを中心にしてモバイルで一番上になるようにする必要がありますが、私の場合はPCでも何が起こっているのか理解していない。ContentDialogがUWPのセンターにアラインメントしていません

私はコードビハインド使用してそれを作成していますが、これは私が使用しているコードの抜粋です:

// Creates the password box 
var passwordBox = new PasswordBox {IsPasswordRevealButtonEnabled = true, Margin = new Thickness(5)};    

// Creates the StackPanel with the content 
var contentPanel = new StackPanel(); 
contentPanel.Children.Add(new TextBlock 
{ 
    Text = "Insert your password to access the application", 
    Margin = new Thickness(5), 
    TextWrapping = TextWrapping.WrapWholeWords 
}); 
contentPanel.Children.Add(passwordBox);  

// Creates the password dialog 
_passwordDialog = new ContentDialog 
{ 
    PrimaryButtonText = "accept", 
    IsPrimaryButtonEnabled = false, 
    SecondaryButtonText = "exit", 
    Title = "Authentication", 
    Content = contentPanel 
}; 

// Report that the dialog has been opened to avoid overlapping 
_passwordDialog.Opened += (s, e) => 
{ 
    // HACK - opacity set to 0 to avoid seeing behind dialog 
    Window.Current.Content.Opacity = 0; 
    _canShowPasswordDialog = false; 
}; 
// Report that the dialog has been closed to enable it again 
_passwordDialog.Closed += (s, e) => 
{ 
    // HACK - opacity set to 1 to reset the window to original options 
    Window.Current.Content.Opacity = 1; 
    _canShowPasswordDialog = true; 
}; 

// Clear inserted password for next logins 
_passwordDialog.PrimaryButtonClick += (s, e) => 
{ 
    // ... login ... 
}; 

// Close the app if the user doesn't insert the password 
_passwordDialog.SecondaryButtonClick += (s, e) => { BootStrapper.Current.Exit(); }; 

// Set the binding to enable/disable the accept button 

_passwordDialog.SetBinding(ContentDialog.IsPrimaryButtonEnabledProperty, new Binding 
{ 
    Source = passwordBox, 
    Path = new PropertyPath("Password"), 
    Mode = BindingMode.OneWay, 
    Converter = new PasswordValidatorConverter() 
}); 

私はすでにVerticalAlignmentFullSizeDesiredを使用してみましたが、私は期待得ることはありません結果。

どうすればこの問題を解決できますか?

+0

を参照してください。 –

答えて

3

ContentDialogは、Popupコントロールのようなもので、ページに表示されている場合はPopupRootが保持します。しかし、Popupコントロールとは異なり、ContentDialogを配置する場所はコードの背後に書かれており、このプロパティは公開されていません。変更することはできません。

私が知っていることから、ContentDialogのデフォルトの動作は、PCを中心にすることです。

ContentDialogは必ずしもPCの中央にあるわけではありません。あなたが投稿したコードのContentDialog塩基をテストします。 640よりも小さいページの高さは、それがページの中央に配置されたときにContentDialogは、ページの上部に位置合わせされたときに我々ができ、上記画像からページ640に等しい高さまたはより大きい640

enter image description here

ContentDialogを配置する場所が、Pageの高さによってトリガーされることを確認してください。ここで

+1

ああ、まあ、それはそれがPCの中心に強制するチャンスがないということですか?そこには本当に醜いですね! – StepTNT

+0

'ApplicationView.PreferredLaunchViewSize = new Size(980,800);を追加できます。 ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;ページの高さを800にします。 –

+0

これはモバイルに影響しますか?アプリケーションウィンドウの最小の高さを設定する方法はありますか? – StepTNT

0

は、方法は次のとおりです。dialog.ShowAsync(ContentDialogPlacement.InPlace):

  1. このように、ダイアログを表示するように配置引数を使用します。
  2. 例えば、あなたのアプリケーションのレイアウトの一部として、あなたのコンテンツダイアログをインスタンス化は、あなたのアプリケーションクラスでは、このようなものを置く:

    private Grid RootGrid => (Grid)Window.Current.Content; 
    private Frame Frame => this.RootGrid?.Children[0] as Frame; 
    private ContentDialog ContentDialog => this.RootGrid?.Children[1] as ContentDialog; 
    
    protected override void OnLaunched(LaunchActivatedEventArgs e) 
    { 
        if (Window.Current.Content == null) { 
         Window.Current.Content = new Grid(); 
         Debug.Assert(this.RootGrid != null); 
         this.RootGrid.Children.Add(new Frame()); 
         this.RootGrid.Children.Add(new ContentDialog()); 
         Debug.Assert(this.Frame != null && this.ContentDialog != null); 
        } 
        ... 
        Window.Current.Activate(); 
    } 
    
  3. はデフォルトでコンテンツダイアログのたHorizo​​ntalAlignment、VerticalAlignmentを、MaxWidthプロパティとMaxHeightのを残しますダイアログの「モーダルの背景」を持つために、アプリの全領域がカバーされます。

P.S.一度に1つのコンテンツダイアログのみが表示されるようにするヒントについては、"Only a single ContentDialog can be open at any time." error while opening another contentdialog

関連する問題