UWP中的ContentDialog,滚动行为错误

时间:2015-11-10 11:56:27

标签: .net xaml win-universal-app uwp

我故意用高StackPanel创建了这个ContentDialog,但即使内容在ScrollViewer中,当内容没有足够的空间时,内容也会被剪裁。那里发生了什么?

<ContentDialog x:Name="ContentDialog">
    <ScrollViewer>
        <StackPanel>
            <Button>Hola</Button>
            <Button>Hola</Button>
            <Button>Hola</Button>
            <Button>Hola</Button>
            <Button>Hola</Button>
            <Button>Hola</Button>
            <Button>Hola</Button>
            <Button>Hola</Button>
            <Button>Hola</Button>
            <Button>Hola</Button>
            <Button>Hola</Button>
            <Button>Hola</Button>
        </StackPanel>
    </ScrollViewer>
</ContentDialog>

但是,页面内的相同内容会正确显示ScrollBars。

3 个答案:

答案 0 :(得分:3)

我改变主意,对不起,我觉得我现在错了! 完美的解决方案是,

https://social.msdn.microsoft.com/Forums/windowsapps/en-US/9112c2fe-1d93-48c9-9638-815be8005b86/uwpwindows-10-uap-scrollviewer-in-contentdialog

“不需要将VerticalScrollBarVisibility值禁用为自动”

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @ 20151122

我和你有同样的问题,我在bing或google中搜索了很多结果。 但都没用。

但哈哈,我找到了一种简单的方法来搞定它。

首先看一下: https://social.msdn.microsoft.com/Forums/windowsapps/en-US/9112c2fe-1d93-48c9-9638-815be8005b86/uwpwindows-10-uap-scrollviewer-in-contentdialog

  

但在我的情况下它也没用。我改变了另一条线并搞了它。

     在ScrollViewer节点中,我修改了VerticalScrollBarVisibility   值禁用为自动并且它搞定。

我的英语很差,希望能帮助你。 我的开发环境是win10版本10240

完整代码:

In [314]:
for col in df:
    df[col] = df[col].shift(-df.index.get_loc(df[col].first_valid_index()))
df

Out[314]:
            col1  col2  col3  col4  col5  col6  col7  col8
STRIP                                                     
01/12/2011   0.8   0.8  0.78   0.7   0.6   0.6   0.1   0.7
01/01/2012   0.8   0.8  0.75   0.7   0.6   0.6   0.2   0.9
01/02/2012   0.8   0.8  0.73   0.7   0.6   0.6   0.3   0.6
01/03/2012   0.8   0.7  0.72   0.7   0.6   0.6   0.4   0.4
01/04/2012   0.7   0.7  0.70   0.7   0.6   0.6   0.5   0.3
01/05/2012   0.7   0.7  0.69   0.7   0.6   0.6   0.8   0.2
01/06/2012   0.7   0.7  0.68   0.7   0.6   0.6   0.7   NaN
01/07/2012   0.7   0.7  0.67   NaN   0.5   0.6   NaN   NaN
01/08/2012   0.7   0.7   NaN   NaN   0.5   NaN   NaN   NaN
01/09/2012   0.7   NaN   NaN   NaN   NaN   NaN   NaN   NaN
02/01/2013   NaN   NaN   NaN   NaN   NaN   NaN   NaN   NaN
03/01/2013   NaN   NaN   NaN   NaN   NaN   NaN   NaN   NaN

答案 1 :(得分:2)

这是因为ScrollViewer的高度设置为&#34; Auto&#34;。尝试将其绑定到ContentDialog的高度:

 <ContentDialog x:Name="ContentDialog">
    <ScrollViewer Height="{Binding ActualHeight, ElementName=ContentDialog}"  >
        <StackPanel>
            <Button>Hola</Button>
            <Button>Hola</Button>
            <Button>Hola</Button>
            <Button>Hola</Button>
            <Button>Hola</Button>
            <Button>Hola</Button>
            <Button>Hola</Button>
            <Button>Hola</Button>
            <Button>Hola</Button>
            <Button>Hola</Button>
            <Button>Hola</Button>
            <Button>Hola</Button>
        </StackPanel>
    </ScrollViewer>
</ContentDialog>

答案 2 :(得分:0)

这里有一个解决方案:标题,文本框和按钮以及ListView 您必须使用此内容模板修改默认ContentDialog o创建新样式以在应用程序的任何ContentDialog中使用它:

<Style x:Key="MyCustomToolsContentDialog"
    TargetType="ContentDialog">
<Setter Property="Template">
    <Setter.Value>
        <ControlTemplate TargetType="ContentDialog">
            <Border x:Name="Container">
                <Grid x:Name="LayoutRoot">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Border x:Name="BackgroundElement"
                            Background="{TemplateBinding Background}"
                            FlowDirection="{TemplateBinding FlowDirection}"
                            BorderThickness="{ThemeResource ContentDialogBorderWidth}"
                            BorderBrush="{ThemeResource SystemControlForegroundAccentBrush}"
                            MaxWidth="{TemplateBinding MaxWidth}"
                            MaxHeight="{TemplateBinding MaxHeight}"
                            MinWidth="{TemplateBinding MinWidth}"
                            MinHeight="{TemplateBinding MinHeight}">
                        <Grid x:Name="DialogSpace"
                                VerticalAlignment="Stretch">
                            <Grid.RowDefinitions>
                                <!-- Modify to 'Height="*"' intead of 'Height="Auto"'-->
                                <RowDefinition Height="*" />
                                <!-- Modify to 'Height="Auto"' intead of 'Height="*"'-->
                                <RowDefinition Height="Auto" />
                                <!-- Delete' RowDefinition -->
                                <!--<RowDefinition Height="Auto" />-->
                            </Grid.RowDefinitions>
                            <ScrollViewer x:Name="ContentScrollViewer"
                                            HorizontalScrollBarVisibility="Disabled"
                                            VerticalScrollBarVisibility="Disabled"
                                            ZoomMode="Disabled"
                                            Margin="{ThemeResource ContentDialogContentScrollViewerMargin}"
                                            IsTabStop="False">
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto" />
                                        <!-- Delete 'Height="Auto"' of RowDefinition.-->
                                        <RowDefinition />
                                    </Grid.RowDefinitions>
                                    <ContentControl x:Name="Title"
                                                    Margin="{ThemeResource ContentDialogTitleMargin}"
                                                    Content="{TemplateBinding Title}"
                                                    ContentTemplate="{TemplateBinding TitleTemplate}"
                                                    FontSize="20"
                                                    FontFamily="Segoe UI"
                                                    FontWeight="Normal"
                                                    Foreground="{TemplateBinding Foreground}"
                                                    HorizontalAlignment="Left"
                                                    VerticalAlignment="Top"
                                                    IsTabStop="False"
                                                    MaxHeight="{ThemeResource ContentDialogTitleMaxHeight}">
                                        <ContentControl.Template>
                                            <ControlTemplate TargetType="ContentControl">
                                                <ContentPresenter Content="{TemplateBinding Content}"
                                                                    MaxLines="2"
                                                                    TextWrapping="Wrap"
                                                                    ContentTemplate="{TemplateBinding ContentTemplate}"
                                                                    Margin="{TemplateBinding Padding}"
                                                                    ContentTransitions="{TemplateBinding ContentTransitions}"
                                                                    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                                            </ControlTemplate>
                                        </ContentControl.Template>
                                    </ContentControl>
                                    <ContentPresenter x:Name="Content"
                                                        ContentTemplate="{TemplateBinding ContentTemplate}"
                                                        Content="{TemplateBinding Content}"
                                                        FontSize="{ThemeResource ControlContentThemeFontSize}"
                                                        FontFamily="{ThemeResource ContentControlThemeFontFamily}"
                                                        Margin="{ThemeResource ContentDialogContentMargin}"
                                                        Foreground="{TemplateBinding Foreground}"
                                                        Grid.Row="1"
                                                        TextWrapping="Wrap" />
                                </Grid>
                            </ScrollViewer>
                            <Grid x:Name="CommandSpace"
                                    Grid.Row="1"
                                    HorizontalAlignment="Stretch"
                                    VerticalAlignment="Bottom">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>
                                <Border x:Name="Button1Host"
                                        Margin="{ThemeResource ContentDialogButton1HostMargin}"
                                        MinWidth="{ThemeResource ContentDialogButtonMinWidth}"
                                        MaxWidth="{ThemeResource ContentDialogButtonMaxWidth}"
                                        Height="{ThemeResource ContentDialogButtonHeight}"
                                        HorizontalAlignment="Stretch" />
                                <Border x:Name="Button2Host"
                                        Margin="{ThemeResource ContentDialogButton2HostMargin}"
                                        MinWidth="{ThemeResource ContentDialogButtonMinWidth}"
                                        MaxWidth="{ThemeResource ContentDialogButtonMaxWidth}"
                                        Height="{ThemeResource ContentDialogButtonHeight}"
                                        Grid.Column="1"
                                        HorizontalAlignment="Stretch" />
                            </Grid>
                        </Grid>
                    </Border>
                </Grid>
            </Border>
        </ControlTemplate>
    </Setter.Value>
</Setter>

此致 Juanlu