正如标题所说,我希望有一个基础为SurfaceButton的组件,点击后会下拉SurfaceScrollViewer。我认为我已经做了正确的第一步,但SurfaceScrollViewer永远不会变得可见,它似乎也没有显示在Blend的层次结构中。我是否错误地访问或初始化了某些内容?我有多个SurfaceDropDown对象实例作为StackPanel的子项,它是另一个SurfaceScrollViewer的内容。此父级滚动查看器在网格中对齐,这就是我使用ActualHeight / Width属性设置高度和宽度的原因。
public class SurfaceDropDown : SurfaceButton
{
public SurfaceScrollViewer scrollViewer;
private StackPanel stackPanel;
public SurfaceDropDown()
{
this.Click += OnClick;
scrollViewer = new SurfaceScrollViewer();
scrollViewer.Height = this.ActualHeight * 5.0;
scrollViewer.Width = this.ActualWidth;
scrollViewer.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
scrollViewer.VerticalAlignment = System.Windows.VerticalAlignment.Center;
scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
scrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
stackPanel = new StackPanel();
for (int i = 0; i < 5; ++i)
{
Label label = new Label();
label.Content = "Label " + i.ToString();
stackPanel.Children.Add(label);
}
scrollViewer.Content = stackPanel;
scrollViewer.ScrollChanged += OnScroll;
this.AddChild(scrollViewer);
}
private void OnClick(object sender, RoutedEventArgs e)
{
scrollViewer.Visibility = scrollViewer.Visibility != Visibility.Visible ? Visibility.Visible : Visibility.Collapsed;
}
private void OnScroll(object sender, RoutedEventArgs e)
{
}
}
非常感谢任何帮助和/或建议!