我创建了一个 WPF 弹出样式并在应用程序的许多地方使用它。弹出标题在样式中定义,我不确定如何在应用程序中将其更改为不同的值,这是样式:
<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>
这就是我调用并希望更改标题以反映弹出内容的方式:
<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>
请帮忙。