好像您正在尝试在弹出窗口周围创建边框
这是一个样本
<Grid>
<ToggleButton Content="open popup"
x:Name="toggle"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
<Popup PlacementTarget="{Binding ElementName=toggle}"
IsOpen="{Binding IsChecked,ElementName=toggle}"
AllowsTransparency="True">
<Border Background="White"
CornerRadius="4"
BorderBrush="Black"
BorderThickness="1"
Padding="5"
Margin="0,0,10,10">
<StackPanel>
<Button Content="somebutton" />
<RadioButton Content="a radiobutton" />
<CheckBox Content="a checkbox" />
</StackPanel>
<Border.Effect>
<DropShadowEffect Opacity=".25" />
</Border.Effect>
</Border>
</Popup>
</Grid>
使用这种方法,即使弹出窗口的某些部分超出了应用程序边界,您也可以绘制边框或阴影
结果
您可以将边框和/或阴影包裹在可重用的样式中以实现重用性
编辑
我试图满足您的要求,还创建了一个可重复使用的模板
<Grid RenderOptions.EdgeMode="Aliased">
<Grid.Resources>
<ControlTemplate TargetType="HeaderedContentControl"
x:Key="PopupButton">
<Grid>
<ToggleButton Content="{TemplateBinding Header}"
x:Name="toggle"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<ToggleButton.Template>
<ControlTemplate TargetType="ToggleButton">
<Border BorderBrush="Gray"
Background="White"
BorderThickness="1"
Padding="4"
x:Name="border">
<StackPanel Orientation="Horizontal">
<ContentPresenter />
<TextBlock Text="▼"
Margin="4,0,0,0"
FontSize="8"
VerticalAlignment="Center" />
</StackPanel>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked"
Value="True">
<Setter Property="BorderThickness"
TargetName="border"
Value="1,1,1,0" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</ToggleButton.Template>
</ToggleButton>
<Popup PlacementTarget="{Binding ElementName=toggle}"
IsOpen="{Binding IsChecked,ElementName=toggle}"
AllowsTransparency="True">
<Grid>
<Border Background="White"
BorderBrush="Gray"
BorderThickness="1"
Padding="5"
Margin="0,0,5,5">
<ContentPresenter />
<Border.Effect>
<DropShadowEffect Opacity=".25" />
</Border.Effect>
</Border>
<Rectangle Fill="White"
Stroke="Transparent"
StrokeThickness="1"
Width="{Binding ActualWidth,ElementName=toggle}"
Height="3"
Margin=".5,-1,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top" />
</Grid>
</Popup>
</Grid>
</ControlTemplate>
</Grid.Resources>
<HeaderedContentControl Header="dev"
Template="{StaticResource PopupButton}">
<StackPanel>
<Button Content="somebutton" />
<RadioButton Content="a radiobutton" />
<CheckBox Content="a checkbox" />
</StackPanel>
</HeaderedContentControl>
</Grid>
您可以在资源中定义模板,在应用中为多个项目定义模板
例如
<HeaderedContentControl Header="header"
Template="{StaticResource PopupButton}">
<!--popup content here-->
</HeaderedContentControl>
结果