【发布时间】:2015-02-10 14:25:10
【问题描述】:
下面是我的代码
<Window x:Class="ScrollTester.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
这里我已经为我在堆栈面板中使用的扩展器的标题设置了数据模板
<DataTemplate x:Key="titleText">
<Border Background="Green" Height="24">
<TextBlock Text="{Binding}"
Width="{Binding
RelativeSource={RelativeSource
Mode=FindAncestor,
AncestorType={x:Type Expander}},
Path=ActualWidth}"/>
</Border>
</DataTemplate>
<Style TargetType="{x:Type Expander}">
<Setter Property="Margin" Value="1,3"/>
<Setter Property="BorderBrush" Value="Gray"/>
<Setter Property="BorderThickness" Value="2"/>
<Setter Property="HeaderTemplate" Value="{StaticResource titleText}"/>
</Style>
</Window.Resources>
我有一个堆栈面板的滚动查看器
<ScrollViewer HorizontalScrollBarVisibility="Auto">
<StackPanel>
<Expander IsExpanded="True" x:Name="general" Header="General">
<StackPanel Orientation="Horizontal">
<GroupBox Header="Mode Control">
<StackPanel>
<CheckBox Content="RESET"/>
<CheckBox Content="MAKEUP" IsChecked="True"/>
<CheckBox Content="POWERDOWN"/>
</StackPanel>
</GroupBox>
<GroupBox Header="Mode Control">
<StackPanel>
<CheckBox Content="RESET"/>
<CheckBox Content="MAKEUP" IsChecked="True"/>
<CheckBox Content="POWERDOWN"/>
</StackPanel>
</GroupBox>
<GroupBox Header="Mode Control">
<StackPanel>
<CheckBox Content="RESET"/>
<CheckBox Content="MAKEUP" IsChecked="True"/>
<CheckBox Content="POWERDOWN"/>
</StackPanel>
</GroupBox>
<GroupBox Header="Mode Control">
<StackPanel>
<CheckBox Content="RESET"/>
<CheckBox Content="MAKEUP" IsChecked="True"/>
<CheckBox Content="POWERDOWN"/>
</StackPanel>
</GroupBox>
<GroupBox Header="Mode Control">
<StackPanel>
<CheckBox Content="RESET"/>
<CheckBox Content="MAKEUP" IsChecked="True"/>
<CheckBox Content="POWERDOWN"/>
</StackPanel>
</GroupBox>
</StackPanel>
</Expander>
</StackPanel>
</ScrollViewer>
这里的问题是即使堆栈面板的宽度更大,滚动条也不起作用。
我可以理解为什么会这样,因为将扩展器的宽度设置为其父级,所以滚动条不起作用
但我希望滚动条工作和启用,以及带有标题样式的数据模板
谁能给出解决方案?
【问题讨论】: