How to write style template to Popup control?
I'd recommend wrapping your Popup's Content in something like a ContentControl
or a HeaderedContentControl
and setting the style of that
<Popup> <ContentControl Style="{StaticResource PopupContentStyle}"> ... </ContentControl></Popup>
Example style...
<Style x:Key="PopupContentStyle" TargetType="{x:Type ContentControl}"> <Setter Property="ContentTemplate"> <Setter.Value> <DataTemplate> <Grid Width="Auto" Height="Auto" Background="Gray"> <Grid.RowDefinitions> <RowDefinition Height="30"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <Border BorderThickness="2" CornerRadius="8" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.RowSpan="2"> <Border.BorderBrush> <SolidColorBrush Color="Gray"/> </Border.BorderBrush> <Border.Background> <SolidColorBrush Color="White"/> </Border.Background> </Border> <StackPanel Grid.Row="0"> <Label Foreground="Blue" Content="Popup_Title"/> </StackPanel> <GroupBox Grid.Row="1" Header="Popup example content"> <StackPanel> <ContentPresenter /> </StackPanel> </GroupBox> </Grid> </DataTemplate> </Setter.Value> </Setter></Style>
I prefer Rachels an Josh Noes answer, but had some trouble, because IMHO one should define ContentControl
s property Template
in Style rather than ContentTemplate
. Set it to a value of ControlTemplate
(not DataTemplate
) and dont forget its TargetType
. Else in my case the solution didn't work. But a real amazing idea, Thank you.
<Style x:Key="PopupContentStyle" TargetType="{x:Type ContentControl}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ContentControl"> ... <!--Do some templatestuff around Presenter--> <ContentPresenter /> <!--/Do some templatestuff around Presenter--> </GroupBox> </Grid> </ControlTemplate> </Setter.Value> </Setter></Style>