10
응용 프로그램 (.NET Framework 4, WPF)에서 많은 팝업을 가지고 있으며 모든 스타일에 하나의 스타일을 설정해야합니다. 예 팝업은 다음과 같습니다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>
어떻게 스타일 템플릿에 테두리와 배경 같은 스타일을 할 수 있습니까? 팝업 컨트롤에 Property="Template"
이 없기 때문에 TargetType Popup을 사용하여 스타일을 쓸 수없고 Property="Template"
을 수정할 수 없습니다. 그렇다면이 팝업에 스타일을 어떻게 써야합니까?
편집 : 정확한 작업 스타일 :
<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>
이 솔루션을 작동시키기 위해 몇 가지 변경 사항을 추가해야했지만이 아이디어는 내가 필요한 것입니다. 고마워요! – Marta
그렇지 않으면이 솔루션이 제대로 작동하지 않아서 ContentPresenter를 이와 같이 정의해야했습니다. 그러나 아이디어 자체가 내가 필요로하는 것입니다 - 감사합니다! –