我试图创建自己的控件。我一直坚持为它添加滚动条。
出于测试目的,我对滚动条值进行了硬编码。
这是我的班级:
public sealed class BarrelPanel : Control
{
public static readonly DependencyProperty VerticalScrollBarVisibilityProperty =
DependencyProperty.Register(
"VerticalScrollBarVisibility", typeof(Visibility),
typeof(BarrelPanel), null);
public Visibility VerticalScrollBarVisibility
{
get { return (Visibility)GetValue(VerticalScrollBarVisibilityProperty); }
set { SetValue(VerticalScrollBarVisibilityProperty, value); }
}
public BarrelPanel()
{
this.DefaultStyleKey = typeof(BarrelPanel);
}
}
这是我的风格:
<Style TargetType="local:BarrelPanel">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:BarrelPanel">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<StackPanel Background="{TemplateBinding Background}"/>
<ScrollBar Grid.Column="1" Maximum="10" Orientation="Vertical" Visibility="{TemplateBinding VerticalScrollBarVisibility}" ViewportSize="1"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
当我将visibility属性设置为enabled时,滚动条将占用网格的一部分:
<local:BarrelPanel HorizontalAlignment="Left" Background="White" Margin="722,212,0,0" VerticalScrollBarVisibility="Visible" VerticalAlignment="Top" Height="217" Width="150"/>
示例:
但它没有显示可拖动的矩形或导航按钮 - 为什么?
答案 0 :(得分:0)
我找到了答案,更多关于msdn的调查:
我的滚动条没有显示,因为必须指定将显示哪种类型的滚动条:
IndicatorMode="MouseIndicator"
或
IndicatorMode="TouchIndicator"
默认情况下没有。