I have created a WPF popup style and using it in many places in the application.
The popup title is defined in the style and I’m not sure how to change it to different values throuhout the application, this is the style:
<Style x:Key="PopupContentStyle1" TargetType="ContentControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ContentControl">
<Grid Height="90" Width="392" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="20"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.092*"></ColumnDefinition>
<ColumnDefinition Width="0.007*"/>
<ColumnDefinition Width="0.054*"/>
<ColumnDefinition Width="0.115*"/>
<ColumnDefinition Width="0.732*"/>
</Grid.ColumnDefinitions>
<Border CornerRadius="10" Grid.ColumnSpan="5">
<Border.Background>
<LinearGradientBrush
EndPoint="0.5,1"
StartPoint="0.5,0">
<GradientStop Color="#FF333C3C"
Offset="0" />
<GradientStop Color="#FF464646"
Offset="0.25" />
<GradientStop Color="#FF504E50"
Offset="0.75" />
<GradientStop Color="#FF595D59"
Offset="1" />
</LinearGradientBrush>
</Border.Background>
<Border Background="{DynamicResource TemplateBackgroundColour}" Margin="5,15,5,5" CornerRadius="5" BorderThickness="0,1,0,0">
<ContentPresenter />
</Border>
</Border>
<Label Name="popupTitle" Content="Sample title" Grid.Column="0" HorizontalAlignment="Center" Height="Auto" Margin="0" VerticalAlignment="Top" Width="Auto" Foreground="{DynamicResource DefaultFontColour}" Padding="0" Grid.ColumnSpan="5" />
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
this is how i call and want to change the title to reflect popup content:
<Popup x:Name="p1" AllowsTransparency="True">
<ContentControl Style="{StaticResource PopupContentStyle1}" >
<ContentControl.Content>
<Grid>
<TextBox>Popup user control goes here</TextBox>
</Grid>
</ContentControl.Content>
</ContentControl>
</Popup>
Please help.
The proper way to do this is making a custom contentcontrol and adding a “popupHeader” dependencyproperty to that class. That way, you can bind your header to that property straight away and you can still use your tag for other purposes.
Make a class like PopUpHeader that inherits from contentcontrol and add a dependencyproperty to it.
Create a class like this:
To be able to reference this in your XAML, input this namespace:
xmlns:local=”clr-namespace:YourNamespace”
where “YourNamespace” is the namespace you have put the above class in.
Then change some targettype attributes in your style:
and also this line
change the binding of the content of your label to:
You can use your new contentcontrol in your xaml like this:
If this would fail, check out the sample app I made for this: download