问题
I am developing an app for windows store using c#/xaml.
Xaml:
<Popup x:Name="EditQuantityPopup"
x:Uid="EditQuantityPopup"
AutomationProperties.AutomationId="EditQuantityPopup"
IsLightDismissEnabled="True"
IsOpen="{Binding IsEditPopupOpened, Mode=TwoWay}">
<Grid x:Name="PopupPanel"
Background="{StaticResource ApplicationPageBackgroundThemeBrush}"
Opacity=".9"
Height="100"
Width="230">
<Grid x:Name="ContentPopupGrid"
Grid.Row="1"
Margin="20,0,10,15">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="Auto" />
<!--<ColumnDefinition />-->
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
Text="{Binding Text}"
VerticalAlignment="Center"
TextTrimming="WordEllipsis"
FontSize="15"
Foreground="White"></TextBlock>
<ProgressRing Grid.Column="2" IsActive="{Binding LoadingData}" Height="75" Width="75"></ProgressRing>
</Grid>
</Grid>
</Popup>
Code placing popout on top of a bottom app bar:
private void EditQuantityPopup_Opened(object sender, object e)
{
int margin = 10;
int appbarHeight = 90;
EditQuantityPopup.HorizontalOffset = margin;
EditQuantityPopup.VerticalOffset = Window.Current.CoreWindow.Bounds.Bottom - appbarHeight - PopupPanel.Height - margin;
}
How to change code that popup should be placed at top right corner of a window?
回答1:
It depends on the layout type or types housing your PopUp element. Try this
EditQuantityPopup.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Right;
EditQuantityPopup.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Top;
Additional to the above depending on your setup you may have to move the PopUp element to a new column in your Grid. eg
Grid.SetColumn(EditQuantityPopup, [your column number]);
If its in a Canvas you could use
var left = Window.Current.Bounds.Width - EditQuantityPopup.ActualWidth;
Canvas.SetLeft(EditQuantityPopup, left);
Canvas.SetTop(EditQuantityPopup, 0);
Hope that helps
来源:https://stackoverflow.com/questions/21220262/place-popup-at-top-right-corner-of-a-window-in-xaml