Ho un sacco di popup in applicazione (.NET Framework 4, WPF) e devo impostare uno stile per tutti loro. Esempio popup sembra che:Come scrivere il modello di stile sul controllo Popup?
<Popup PopupAnimation="Fade" MinWidth="600" MinHeight="200" Placement="Center" VerticalAlignment="Center" HorizontalAlignment="Center" IsEnabled="True" IsOpen="False">
<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>
...
</StackPanel>
</GroupBox>
</Grid>
</Popup>
Come posso prendere stili come i bordi e lo sfondo per un modello di stile? Non riesco a scrivere Style con TargetType Popup e modificarlo è Property="Template"
perché Popup Control non ha Property="Template"
. Quindi, come posso scrivere lo stile su quei Popup?
EDIT: stile di lavoro esatta:
<Style x:Key="PopupContentStyle" TargetType="ContentControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ContentControl">
<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>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Ho dovuto aggiungere alcune modifiche per far funzionare questa soluzione, ma questa idea era esattamente ciò di cui avevo bisogno. Molte grazie! – Marta
Ho dovuto definire ContentPresenter in questo modo, perché altrimenti questa soluzione non funzionava. Ma l'idea stessa è ciò di cui ho bisogno, grazie anche a me! –