在XAML WPF中创建并打开无模窗口/弹出窗口

时间:2012-07-16 15:47:04

标签: wpf popup window modeless

是否可以创建一个可以在XAML中单击按钮打开的无模式窗口/弹出窗口。我需要能够并排查看父窗口和子模块窗口。 无模窗口最初需要适合我的网格,并且在点击它时需要扩展到父级别。

弹出控件有多个错误。展开时弹出控件的高度不是100%的屏幕高度,只有75%的屏幕高度。 弹出控件也需要太多时间来加载数据。

以下是我设置具有Popup的扩展器控件的方式。

  <Style TargetType="Expander" x:Key="NotesSlider">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Expander" >
                    <Grid  HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                           Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Grid}} ,Path=ActualWidth}" 
                           Height="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Grid}} ,Path=ActualHeight}"
                           x:Name="GridMain">
                        <Border x:Name="popupBorder" BorderBrush="White">
                            <!--<Popup IsOpen="True" PopupAnimation="Slide" x:Name="SlideOut" StaysOpen="True"
                            Placement="Relative" AllowsTransparency="True" Grid.Column="0" Width="Auto" Height="Auto">-->
                            <controls:PopupNonTopmost IsOpen="True" PopupAnimation="None" Placement="Relative" AllowsTransparency="True" StaysOpen="True"
                                             Topmost="False"  x:Name="SlideOut" Panel.ZIndex="10000" >

                                <Grid Margin="0 0 0 10" x:Name="gridContainer">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*"/>
                                    </Grid.ColumnDefinitions>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto" x:Name="NoteHeaderRow"/>
                                        <RowDefinition Name="NotesContentRow" Height="0"/>
                                    </Grid.RowDefinitions>

                                    <Border 
                                Name="NoteBorder" 
                                Grid.Row="0" 
                                Background="{StaticResource NormalBrush}"
                                BorderBrush="{StaticResource NormalBorderBrush}"
                                BorderThickness="1" 
                                CornerRadius="0" >
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="*" />
                                                <ColumnDefinition Width="20" />
                                                <ColumnDefinition Width="20" />
                                            </Grid.ColumnDefinitions>

                                            <ContentPresenter 
                            Grid.Column="0"
                            Margin="4" 
                            ContentSource="Header" 
                            RecognizesAccessKey="True" />

                                            <ToggleButton
                            IsChecked="{Binding Path=IsExpanded,Mode=TwoWay,
                            RelativeSource={RelativeSource TemplatedParent}}"
                            OverridesDefaultStyle="True" 
                            Grid.Column="1"
                            Template="{StaticResource VerticalExpanderToggleButton}" 
                            Background="{StaticResource NormalBrush}" />

                                            <ToggleButton  x:Name="toggleMax"
                            OverridesDefaultStyle="True" 
                            Grid.Column="2"
                            Template="{StaticResource SliderToggleButton}" 
                            Background="{StaticResource NormalBrush}" />

                                        </Grid>
                                    </Border>

                                    <Border 
                    Name="NoteContent" 
                    Grid.Row="1" 
                    Background="{StaticResource WindowBackgroundBrush}"
                    BorderBrush="{StaticResource SolidBorderBrush}" 
                    BorderThickness="1,0,1,1" 
                    CornerRadius="0" >
                                        <ContentPresenter Margin="4" x:Name="content"/>
                                    </Border>

                                </Grid>


                            </controls:PopupNonTopmost>
                            <!--</Popup>-->
                        </Border>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsChecked" Value="True" SourceName="toggleMax">
                            <Setter TargetName="SlideOut" Property="PlacementTarget" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Window}}}"/>
                            <Setter TargetName="SlideOut" Property="Width" Value="{Binding Source={x:Static SystemParameters.WorkArea}, Path=Width,Converter={StaticResource PopupWidthConverter}}"/>
                            <Setter TargetName="SlideOut" Property="Height" Value="{Binding Source={x:Static SystemParameters.WorkArea}, Path=Height,Converter={StaticResource PopupHeightConverter}}"/>
                            <Setter TargetName="popupBorder" Property="BorderBrush" Value="Black"/>
                            <!--<Setter TargetName="SlideOut" Property="Width" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Window}},Path=Width}"/>
                            <Setter TargetName="SlideOut" Property="Height" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Window}},Path=ActualHeight}"/>-->


                        </Trigger>

                        <Trigger Property="IsChecked" Value="False" SourceName="toggleMax">
                            <Setter TargetName="SlideOut" Property="PlacementTarget" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Grid}}}"/>
                            <Setter TargetName="SlideOut" Property="Width" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Grid}},Path=Width}"/>
                            <Setter TargetName="SlideOut" Property="Height" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Grid}},Path=Height}"/>

                        </Trigger>


                        <Trigger Property="IsExpanded" Value="True">
                            <Setter TargetName="NotesContentRow" Property="Height" Value="{Binding ElementName=Content,Path=DesiredHeight}" />

                        </Trigger>

                        <Trigger Property="IsEnabled" Value="False">
                            <Setter TargetName="NoteBorder" Property="Background"
                                    Value="{StaticResource DisabledBackgroundBrush}" />
                            <Setter TargetName="NoteBorder" Property="BorderBrush"
                                    Value="{StaticResource DisabledBorderBrush}" />
                            <Setter Property="Foreground"
                                    Value="{StaticResource DisabledForegroundBrush}"/>
                        </Trigger>


                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

1 个答案:

答案 0 :(得分:0)

我认为Popup已知问题。 它已在此处记录: http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.placementmode%28VS.85%29.aspx

所以我必须在不使用弹出控件的情况下以另一种方式做到这一点。