WPF Code-behind Expander不会扩展

时间:2015-07-04 06:24:20

标签: c# wpf scrollviewer stackpanel expander

我用扩展器填充StackPanel,但它们似乎没有扩展。我已经开始测试它的Button.Click事件以确保所有功能正常运行(它是),所以我不明白为什么它不会扩展。上面提到的StackPanel是SurfaceScrollViewer的内容,当扩展器扩展时,正常行为(如Blend中所示)是将ToggleButton / Header对齐到SurfaceScrollViewer的顶部。我对WPF比较陌生,所以也许我错过了一些小事?此自动对齐/焦点行为还有更多内容吗?

XAML:

<s:SurfaceScrollViewer Name="TimeScrollViewer" Grid.Row="1" Grid.Column="1" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Background="#4CAAAAFF" Style="{DynamicResource SurfaceScrollViewerHorizontalTop}" Foreground="#4CAAAAFF">
    <StackPanel Name="TimeStackPanel" Orientation="Horizontal" HorizontalAlignment="Left"/>
</s:SurfaceScrollViewer>

C#:

public MainWindow()
{
    InitializeComponent();

    Loaded += delegate
    {
        PopulateScrollViewer(new string[] { "5:00", "5:30", "6:00", "6:30", "7:00", "7:30", "8:00", "8:30", "9:00", "9:30" });
    };
}

public void PopulateScrollViewer(string [] contents)
{
    Style expanderStyle = FindResource("SurfaceExpander") as Style;

    foreach (string s in contents)
    {
        Expander expander = new Expander();

        expander.Style = FindResource("SurfaceExpander") as Style;
        expander.Header = s;
        expander.HorizontalAlignment = HorizontalAlignment.Center;
        expander.FontSize = 21.333;
        expander.Width = TimeScrollViewer.ActualWidth * 0.25;
        expander.Height = TimeScrollViewer.ActualHeight * 0.4;

        Label label = new Label();

        label.Content = "test";

        expander.Content = label;

        TimeStackPanel.Children.Add(expander);
    } 
}

我宁愿不用整个风格轰炸你,而是用#34; SurfaceScrollViewerHorizo​​ntalTop&#34;将水平滚动条放在内容的顶部,以及&#34; SurfaceExpander&#34;删除指示箭头。

0 个答案:

没有答案