UWP:如何在窗格关闭时指定窗格边框?

时间:2016-05-11 11:19:02

标签: c# xaml win-universal-app windows-10-universal

只是一个简单的问题,我正在使用SplitView,并且当窗格关闭时我尝试创建左边框。 (注意:我将窗格放在右边)。

有可能吗?我试过了:

<SplitView DisplayMode="CompactOverlay" IsPaneOpen="False" OpenPaneLength="320" PanePlacement="Right">
    <SplitView.Pane>
        <Border BorderBrush="black" BorderThickness="1 0 0 0">
            ...
            ...
            ...
        </Border>
    </SplitView.Pane>
    <SplitView.Content>
        ...
        ...
        ...
    </SplitView.Content>
</SplitView>

但是只有在我打开窗格时才会出现边框。

很抱歉这个愚蠢的问题,但UWP对我来说是新的。

感谢。

1 个答案:

答案 0 :(得分:0)

使用控件的默认样式是不可能的。 默认情况下,visibility属性设置为collapsed时,窗格IsPaneOpen设置为false

如果您想这样做,则必须为splitview创建自己的样式。

这是默认样式(已删除可视状态管理器)

<Style TargetType="SplitView">
    <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
    <Setter Property="VerticalContentAlignment" Value="Stretch"/>
    <Setter Property="OpenPaneLength" Value="{ThemeResource SplitViewOpenPaneThemeLength}"/>
    <Setter Property="CompactPaneLength" Value="{ThemeResource SplitViewCompactPaneThemeLength}"/>
    <Setter Property="PaneBackground" Value="{ThemeResource SystemControlPageBackgroundChromeLowBrush}"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="SplitView">
                <Grid Background="{TemplateBinding Background}">


                    <!-- Content Area -->
                    <Grid x:Name="ContentRoot" Grid.ColumnSpan="2">
                        <Border Child="{TemplateBinding Content}"/>
                        <Rectangle x:Name="LightDismissLayer" Fill="Transparent" Visibility="Collapsed"/>
                    </Grid>

                    <!-- Pane Content Area-->
                    <Grid
                        x:Name="PaneRoot"
                        Grid.ColumnSpan="2"
                        HorizontalAlignment="Left"
                        Visibility="Collapsed"
                        Background="{TemplateBinding PaneBackground}"
                        Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.OpenPaneLength}">
                        <Grid.Clip>
                            <RectangleGeometry x:Name="PaneClipRectangle">
                                <RectangleGeometry.Transform>
                                    <CompositeTransform x:Name="PaneClipRectangleTransform"/>
                                </RectangleGeometry.Transform>
                            </RectangleGeometry>
                        </Grid.Clip>
                        <Grid.RenderTransform>
                            <CompositeTransform x:Name="PaneTransform"/>
                        </Grid.RenderTransform>
                        <Border Child="{TemplateBinding Pane}"/>
                        <Rectangle
                            x:Name="HCPaneBorder"
                            x:DeferLoadStrategy="Lazy"
                            Visibility="Collapsed"
                            Fill="{ThemeResource SystemControlForegroundTransparentBrush}"
                            Width="1"
                            HorizontalAlignment="Right"/>
                    </Grid>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>