This project has moved. For the latest updates, please go here.

ChildWindow center issue when content size is changed

May 15, 2013 at 8:38 AM
Edited May 15, 2013 at 8:39 AM
I've faced a problem that the child window was not centered correctly if the content was changed.

Actually, it always remembers its previous position. Let's see below example.
  1. Click "Small Dialog" button, it shows at the center of its parent
  2. Click "Big Dialog" button, it shows at its previous position, although its content size has been changed.
  3. Click "Big Dialog" button agaian, it shows at the center of its parent
Does any one know how to resolve this issue?
    <Grid>
        <StackPanel>
            <Button Name="_smallDialogButton"
                    Content="Show Small Dialog"
                    Click="_smallDialogButton_OnClick"
                    Margin="10" />
            <Button Name="_bigDialogButton"
                    Content="Show Big Dialog"
                    Click="_bigDialogButton_OnClick"
                    Margin="10" />
        </StackPanel>
        <toolkit:ChildWindow x:Name="_dialog" IsModal="True" WindowStartupLocation="Center" Content="{Binding}">
            <toolkit:ChildWindow.Resources>
                <DataTemplate DataType="{x:Type vm:SmallContent}">
                    <Grid Background="Red" Width="300" Height="300" />
                </DataTemplate>
                <DataTemplate DataType="{x:Type vm:BigContent}">
                    <Grid Background="Blue" Width="600" Height="600" />
                </DataTemplate>
            </toolkit:ChildWindow.Resources>
        </toolkit:ChildWindow>
    </Grid>
    public partial class CustomDialogSample : UserControl
    {
        public CustomDialogSample()
        {
            InitializeComponent();
        }

        private void _smallDialogButton_OnClick(object sender, RoutedEventArgs e)
        {
            _dialog.DataContext = new SmallContent();
            _dialog.WindowState = WindowState.Open;
        }

        private void _bigDialogButton_OnClick(object sender, RoutedEventArgs e)
        {
            _dialog.DataContext = new BigContent();
            _dialog.WindowState = WindowState.Open;
        }
    }

    public class SmallContent
    {
        
    }

    public class BigContent
    {
        
    }
Developer
May 15, 2013 at 11:57 AM
An Issue has been created for this : https://wpftoolkit.codeplex.com/workitem/19714.