When you do this, it means that the entire contents of the user control is replaced with the content you provided.
<custom:FullWidthExpander Width="200" HeaderBackground="Gray"> <Button /> </custom:FullWidthExpander>
To get around this you need to host the content little bit differently in your usercontrol
First add a dependency property for the user control
public object UserControlContent { get { return (object)GetValue(UserControlContentProperty); } set { SetValue(UserControlContentProperty, value); } } public static readonly DependencyProperty UserControlContentProperty = DependencyProperty.Register("UserControlContent", typeof(object), typeof(FullWidthExpander), new PropertyMetadata(null));
Then bind this to the contentpresenter in the usercontrol's xaml also define a name for your usercontrol like x:Name="Root".
<Expander Header="My expander header"> <Expander.Template> <ControlTemplate> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="15"/> </Grid.RowDefinitions> <ContentPresenter x:Name="ContentPresenter" Grid.Row="0" Content="{Binding UserControlContent, ElementName=Root}" /> <ToggleButton Grid.Row="1" Content="Togglebutton"> </ToggleButton> </Grid> </ControlTemplate> </Expander.Template> </Expander>
And finally you define the content content in maindwindow xaml as such
<custom:FullWidthExpander> <custom:FullWidthExpander.UserControlContent> <Button Content="Click me"/> </custom:FullWidthExpander.UserControlContent> </custom:FullWidthExpander>
ControlTemplatedefined at? And am I safe to assume thatFullWidthExpanderis a customUserControl? I did a quick test with a normal Expander in just XAML in the MainWindow and it works just fine, so my guess is your problem has something to do with your control hierarchy.