2015-12-29 40 views
1

在我的WPF应用程序中,我在MainWindow上有图像图标,并且在图像单击时显示/隐藏弹出窗口。在wpf中调整父窗口大小时弹出窗口在父窗口外面

弹出窗口的Placement属性是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> 

回答

1

集“安置”为XAML中的“自定义”弹出窗口的属性,然后在后面的代码设置其身高,体重和位置上OptionsMenuPopup.CustomPopupPlacementCallback处理器。尝试它会工作。

+0

您是否试过这种解决方案? –

+0

是的..谢谢你abhishek它的工作.. –

+0

哦,太棒了,欢迎。 –