Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Cannot find the Style Property 'Template' on the type 'System.Windows.Controls.Primitives.Popup'

I have to create style for popups. I am using WPF and .NET Framework 4.

I have written style:

<Style x:Key="PopupBox" TargetType="{x:Type Popup}">   
    <Setter Property="OverridesDefaultStyle" Value="True" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Popup}">       
                <Grid>  
                    <Border BorderBrush="Blue" Background="#FFFFFFFF">
                        <Grid>                                
                            <Border Background="AliceBlue"/>  
                            <ContentPresenter ContentSource="Header" /> 
                            <ContentPresenter/>
                            <Border BorderBrush="#FFFFFFFF" Background="#FFBFDBFF"/>
                        </Grid>
                    </Border>
                </Grid>                    
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style> 

I have cut off from this code some elements like grid row and column definitions because they are not significant.

So it seems that I can't use <Setter Property="Template"> because Popup control doesn't have this property. How can I work around this?

Any help here much appreciated!

like image 997
Marta Avatar asked Jan 29 '26 07:01

Marta


1 Answers

As Popup doesn`t have any template and just a Child property for content, you can use some other control (for example ContentControl) to style and template:

<Style x:Key="PopupContentStyle" TargetType="ContentControl">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ContentControl">
                <Border BorderBrush="Blue" Background="#FFFFFFFF">
                    <Grid>                                
                        <Border Background="AliceBlue"/>  
                        <ContentPresenter/>
                        <Border BorderBrush="#FFFFFFFF" Background="#FFBFDBFF"/>
                    </Grid>
                </Border>
            </ControlTemplate>
        </Setter.Value>
     </Setter>
</Style>

Then just place it in every Popup that needs it:

<Popup>
    <ContentControl Style="{StaticResource PopupContentStyle}">
       <!-- Some content here -->
    </ContentControl>
</Popup>
like image 131
icebat Avatar answered Jan 30 '26 23:01

icebat