在我的WPF应用程序中,我在MainWindow上有图像图标,我在点击图像时显示/隐藏弹出窗口。
弹出窗口的放置属性为bottom,PlacementTarget设置为image。
问题 - 一切正常但是当我调整MainWindow的大小时,一半的弹出窗口就在MainWindow之外。它必须是MainWindow的内部边界。弹出窗口应仅显示在图像图标的底部。
我的弹出窗口代码窗口......
<Popup Name="popup" AllowsTransparency="True"
Placement="Bottom" MouseDown="popup_MouseDown"
PlacementTarget="{Binding ElementName=TriangleIcon}">
<Border BorderThickness="3" BorderBrush="Gray"
Background="White" Height="150">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="5" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="3" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="3" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="10"/>
<RowDefinition/>
<RowDefinition Height="10"/>
<RowDefinition/>
<RowDefinition Height="10"/>
<RowDefinition/>
<RowDefinition Height="10"/>
<RowDefinition/>
<RowDefinition Height="10"/>
<RowDefinition/>
<RowDefinition Height="
</Grid.RowDefinitions>
<TextBlock Grid.Row="1" Grid.Column="1"
Grid.ColumnSpan="5" FontSize="15"
Foreground="Gray" HorizontalAlignment="Center">
Dashboard Settings </TextBlock>
<TextBlock Grid.Row="3" Grid.Column="1"
Grid.ColumnSpan="5" HorizontalAlignment="Left">
Local Rate : 12 $/kw. Click to change.</TextBlock>
<Button Width="50" Grid.Row="5" Grid.Column="1">Save</Button>
<Button Width="50" Grid.Row="7" Grid.Column="1">Print</Button>
<Button Width="50" Grid.Row="9"
Grid.Column="1">Log</Button>
</Grid>
</ScrollViewer>
</Border>
</Popup>
答案 0 :(得分:1)
在Xaml中将弹出窗口的“Placement”属性设置为“Custom”,然后在后面的代码中将其高度,重量和位置设置为OptionsMenuPopup.CustomPopupPlacementCallback处理程序。试试它会起作用。