Quantcast
Channel: Extended WPF Toolkit™ Community Edition
Viewing all articles
Browse latest Browse all 4964

Commented Issue: ChildWindow center issue when content size is changed [19713]

$
0
0
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
{

}
```
Comments: ** Comment from web user: yyytiger **

I was able to figure out the solution by calling UpdateLayout before showing the child window.


_dialog.DataContext = new BigContent();
_dialog.UpdateLayout();
_dialog.WindowState = WindowState.Open;

[TEXT](http://stackoverflow.com/questions/6029299/determining-size-of-a-control-before-rendering-process)


Viewing all articles
Browse latest Browse all 4964

Trending Articles