Den*_*der 9 wpf xaml blend scrollviewer
我还没有找到Blend/WPF的这个问题的信息.仅适用于Eclipse,这无济于事.
我目前正在设计一个WPF 4应用程序对话框.它应该是一个ScrollViewer具有不同元素的StackPanel:
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Height="470" VerticalAlignment="Top">
  <StackPanel Height="1893" Width="899">
    <!-- Elements here ... -->
  </StackPanel>
<ScrollViewer>
到目前为止一切都按预期工作.滚动条可见.我的问题是我无法在Blend或Visual Studio 2012中向下滚动设计时间.运行项目工作正常,用户可以向下滚动到其他对象.
但在设计时,似乎没有机会向下滚动以准确定位(现在隐藏)控件.
一个解决方案是扩展控件以显示完整的内容.但这不是最好的解决方案.有没有人有设计时适当滚动的线索?
非常感谢你.
Viv*_*Viv 12
不要认为存在开箱即用的设计时属性.但是你可以很容易地自己创建一个.
说出类似的话:
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
public static class CustomDesignAttributes {
  private static bool? _isInDesignMode;
  public static DependencyProperty VerticalScrollToProperty = DependencyProperty.RegisterAttached(
    "VerticalScrollTo",
    typeof(double),
    typeof(CustomDesignAttributes),
    new PropertyMetadata(ScrollToChanged));
  public static DependencyProperty HorizontalScrollToProperty = DependencyProperty.RegisterAttached(
    "HorizontalScrollTo",
    typeof(double),
    typeof(CustomDesignAttributes),
    new PropertyMetadata(ScrollToChanged));
  private static bool IsInDesignMode {
    get {
      if (!_isInDesignMode.HasValue) {
        var prop = DesignerProperties.IsInDesignModeProperty;
        _isInDesignMode =
          (bool)DependencyPropertyDescriptor.FromProperty(prop, typeof(FrameworkElement)).Metadata.DefaultValue;
      }
      return _isInDesignMode.Value;
    }
  }
  public static void SetVerticalScrollTo(UIElement element, double value) {
    element.SetValue(VerticalScrollToProperty, value);
  }
  public static double GetVerticalScrollTo(UIElement element) {
    return (double)element.GetValue(VerticalScrollToProperty);
  }
  public static void SetHorizontalScrollTo(UIElement element, double value) {
    element.SetValue(HorizontalScrollToProperty, value);
  }
  public static double GetHorizontalTo(UIElement element) {
    return (double)element.GetValue(HorizontalScrollToProperty);
  }
  private static void ScrollToChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
    if (!IsInDesignMode)
      return;
    ScrollViewer viewer = d as ScrollViewer;
    if (viewer == null)
      return;
    if (e.Property == VerticalScrollToProperty) {
      viewer.ScrollToVerticalOffset((double)e.NewValue);
    } else if (e.Property == HorizontalScrollToProperty) {
      viewer.ScrollToHorizontalOffset((double)e.NewValue);
    }
  }
}
现在通过在xaml中设置自定义附加属性,例如:
<ScrollViewer Height="200"
              local:CustomDesignAttributes.VerticalScrollTo="50">
...
仅在设计时,您应该能够使用滚动偏移量来查看您的设计

而在实际运行时,控件将不被触及.该CustomDesignAttributes也有类似性质local:CustomDesignAttributes.HorizontalScrollTo的水平在设计时偏移.