Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 如何设置对话框演示者中心屏幕?_Wpf_Templates_Xaml_Custom Controls_Modal Dialog - Fatal编程技术网

Wpf 如何设置对话框演示者中心屏幕?

Wpf 如何设置对话框演示者中心屏幕?,wpf,templates,xaml,custom-controls,modal-dialog,Wpf,Templates,Xaml,Custom Controls,Modal Dialog,我用的是Brads 它工作得很好,但我只有一个问题 我无法获取它,因此对话框显示中心屏幕 有人能帮我吗。有几种方法可以使对话框居中 在DialogPresenter类中,更新Show()方法以设置window.WindowsStartUpposition=WindowsStartUpLocation.CenterScreen 编写一个自定义TriggerAction并重写Invoke以执行以下操作 var window=window.GetWindow(this.AssociatedObject

我用的是Brads

它工作得很好,但我只有一个问题

我无法获取它,因此对话框显示中心屏幕


有人能帮我吗。

有几种方法可以使对话框居中

  • 在DialogPresenter类中,更新Show()方法以设置window.WindowsStartUpposition=WindowsStartUpLocation.CenterScreen

  • 编写一个自定义TriggerAction并重写Invoke以执行以下操作

    var window=window.GetWindow(this.AssociatedObject); window.WindowStartupLocation.CenterScreen

    然后将触发器操作附加到触发器部分中的ControlTemplate。您可以使用LoadedEvent并调用TriggerAction来使用EventTrigger

  • 注意:如果您有ExpressionBlend,它可以轻松地将TriggerActions拖动到UI,因为它为您编写EventTrigger部分。

    为我工作

    在DialogPresenter.Generic.xaml中

    <controls:DragCanvas Name="DialogCanvas">
      <Grid x:Name="Dialog"  ...>
        <Canvas.Top>
            <MultiBinding Converter="{StaticResource CenterConverter}" ConverterParameter="top">
                <Binding ElementName="DialogCanvas" Path="ActualWidth" />
                <Binding ElementName="DialogCanvas" Path="ActualHeight" />
                <Binding ElementName="Dialog" Path="ActualWidth" />
                <Binding ElementName="Dialog" Path="ActualHeight" />
            </MultiBinding>
        </Canvas.Top>
        <Canvas.Left>
            ...
        </Canvas.Left>
    
    
    ...