2

I am using Brads Dialog Presenter.

It works great, but i only have 1 problem...

I can't get it so that the dialog shows Center Screen.

Can anyone help me here please.

Community
  • 1
  • 1
Willem
  • 9,166
  • 17
  • 68
  • 92

2 Answers2

1

This converter worked for me.

In 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>
Community
  • 1
  • 1
Najera
  • 2,869
  • 3
  • 28
  • 52
0

There are a couple of ways you can get the dialog centered.

  1. In the DialogPresenter class, update the Show() method to set the window.WindowStartupPosition = WindowStartupLocation.CenterScreen.

  2. Write a custom TriggerAction and override Invoke to do the following.

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

    then attach the trigger action to the ControlTemplate in the triggers section. You would use an EventTrigger using the LoadedEvent and calling your TriggerAction.

Note: If you have ExpressionBlend, it makes dragging TriggerActions to the UI easy because it writes the EventTrigger part for you.

Geoff Cox
  • 6,102
  • 2
  • 27
  • 30