none
如何用Popup 做出ShowDialog的效果,出现全屏遮罩层居中 RRS feed

答案

  • 你好,

    我们可以设置Popup的放置位置(Placement)为居中(Center), PlacementTarget为想遮盖的容器,高度和宽度也是通过和Target的实际宽高绑定:

    <Grid Name="grid" Background="LightBlue">
            <ComboBox Name="cbx" Panel.ZIndex="1" Height="25" Width="100" SelectionChanged="cbx_SelectionChanged">
                <ComboBoxItem Content="Item1" />
                <ComboBoxItem Content="Item2" />
                <ComboBoxItem Content="Item3" />
                <ComboBoxItem Content="Item4" />
                <ComboBoxItem Content="Item5" />
            </ComboBox>
            <Popup Name="rootPopup" Height="{Binding ActualHeight, ElementName=grid}" Width="{Binding ActualWidth, ElementName=grid}" PlacementTarget="{Binding ElementName=grid}" Placement="Center">
                <Grid Background="White" >
                    <TextBlock Name="rootPopupText" Height="25" Width="100"
                           Background="LightBlue" 
                           Foreground="Red">
                        Popup Text
                    </TextBlock>
                </Grid>
            </Popup>
    </Grid>

    private void cbx_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
                rootPopupText.Text = "asdsadasdsadasd";
                rootPopup.IsOpen = true;
    }

    截图:

    参考文章:

    #Popup Placement Behavior
    http://msdn.microsoft.com/en-us/library/bb613596(v=vs.110).aspx

    #How to: Specify a Custom Popup Position
    http://msdn.microsoft.com/en-us/library/ms743607(v=vs.110).aspx


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2014年8月19日 2:44
    版主