的ScrollViewer中下面的是我的代碼寬度影響外
<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中爲我使用的堆棧面板
<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>
滾動觀看者
這裏的問題是,即使堆棧面板的寬度更大,滾動條也不起作用。
我能理解爲什麼它會發生,因爲設置擴展到其父的寬度,這樣滾動條不工作
但我想無論是滾動條的工作和啓用以及與風格的DataTemplate爲標題
任何人都可以給解決方案?
謝謝,我創建了我自己的模板 – keerthee 2015-02-11 06:22:19