<sdk:DataGrID name="dgMain" ItemsSource="{Binding SomeSource}" /><toolkit:Accordion> <toolkit:AccordionItem header="Details"> <sdk:DataGrID ItemsSource="{Binding Elementname=dgMain,Path=SelectedItem.Children}"/> </toolkit:AccordionItem></toolkit:Accordion>
我将第二个网格的VerticalAlignment属性设置为“Stretch”,所以它随着不同的集合大小而被拉伸,但问题是它只在AccordionItem大小中延伸,所以如果我在第一个网格中选择了一个新项目“儿童”,因为AccordionItem没有改变,所以我必须滚动第二个网格.
AccordionItem区域只会在我凝结并再次展开时发生变化.将VerticalContentAlignment设置为手风琴项目的“拉伸”不起作用.我猜是因为它只是在第一次展开时触发这个.
有人知道还有什么可以尝试,还是我错过了什么.我更喜欢坚持xaml解决方案,所以我可以保持MVVM友好,但很高兴听到一切.
解决方法 AccordionItem没有正确调整大小的原因是因为它的一个控件部分 – ExpandableContentControl中有一个错误.问题描述为 here.我想你可以修复它的源代码,或者更容易地,使用正常的ContentControl将其从默认样式替换.我在这里包含一个正常的ContentControl的样式,并在@JohnNicholas提供的代码中进行测试,它的工作原理.
<Style targettype="toolkit:AccordionItem"> <Setter Property="borderThickness" Value="1"/> <Setter Property="borderBrush" Value="#FFECECEC"/> <Setter Property="Background" Value="White"/> <Setter Property="margin" Value="0"/> <Setter Property="padding" Value="0"/> <Setter Property="HorizontalAlignment" Value="Stretch"/> <Setter Property="VerticalAlignment" Value="Stretch"/> <Setter Property="HorizontalContentAlignment" Value="left"/> <Setter Property="VerticalContentAlignment" Value="top"/> <Setter Property="IsTabStop" Value="False"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate targettype="toolkit:AccordionItem"> <GrID Background="{TemplateBinding Background}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}"> <visualstatemanager.VisualStateGroups> <VisualStateGroup x:name="CommonStates"> <VisualStateGroup.Transitions> <VisualTransition GeneratedDuration="0"/> </VisualStateGroup.Transitions> <VisualState x:name="normal"/> <VisualState x:name="pressed"/> <VisualState x:name="MouSEOver"/> <VisualState x:name="Disabled"/> </VisualStateGroup> <VisualStateGroup x:name="Focusstates"> <VisualState x:name="Focused"/> <VisualState x:name="Unfocused"/> </VisualStateGroup> <VisualStateGroup x:name="ExpansionStates"> <VisualStateGroup.Transitions> <VisualTransition GeneratedDuration="0"/> </VisualStateGroup.Transitions> <VisualState x:name="Collapsed"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.Targetname="ExpandSite"> <discreteObjectKeyFrame KeyTime="0"> <discreteObjectKeyFrame.Value> <Visibility>Collapsed</Visibility> </discreteObjectKeyFrame.Value> </discreteObjectKeyFrame> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState x:name="Expanded"> </VisualState> </VisualStateGroup> <VisualStateGroup x:name="LockedStates"> <VisualStateGroup.Transitions> <VisualTransition GeneratedDuration="0"/> </VisualStateGroup.Transitions> <VisualState x:name="Locked"> <Storyboard> <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="IsEnabled" Storyboard.Targetname="Expanderbutton"> <discreteObjectKeyFrame KeyTime="0" Value="False"/> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState x:name="Unlocked"> <Storyboard> <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="IsEnabled" Storyboard.Targetname="Expanderbutton"> <discreteObjectKeyFrame KeyTime="0" Value="True"/> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> </VisualStateGroup> <VisualStateGroup x:name="ExpandDirectionStates"> <VisualStateGroup.Transitions> <VisualTransition GeneratedDuration="0"/> </VisualStateGroup.Transitions> <VisualState x:name="ExpandDown"> <Storyboard> <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Height" Storyboard.Targetname="rd1"> <discreteObjectKeyFrame KeyTime="0" Value="*"/> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="WIDth" Storyboard.Targetname="cd0"> <discreteObjectKeyFrame KeyTime="0" Value="*"/> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState x:name="ExpandUp"> <Storyboard> <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="(GrID.Row)" Storyboard.Targetname="Expanderbutton"> <discreteObjectKeyFrame KeyTime="0" Value="1"/> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="(GrID.Row)" Storyboard.Targetname="ExpandSite"> <discreteObjectKeyFrame KeyTime="0" Value="0"/> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Height" Storyboard.Targetname="rd0"> <discreteObjectKeyFrame KeyTime="0" Value="*"/> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="WIDth" Storyboard.Targetname="cd0"> <discreteObjectKeyFrame KeyTime="0" Value="*"/> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState x:name="Expandleft"> <Storyboard> <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="(GrID.ColumnSpan)" Storyboard.Targetname="Expanderbutton"> <discreteObjectKeyFrame KeyTime="0" Value="1"/> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="(GrID.ColumnSpan)" Storyboard.Targetname="ExpandSite"> <discreteObjectKeyFrame KeyTime="0" Value="1"/> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="(GrID.rowspan)" Storyboard.Targetname="Expanderbutton"> <discreteObjectKeyFrame KeyTime="0" Value="2"/> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="(GrID.rowspan)" Storyboard.Targetname="ExpandSite"> <discreteObjectKeyFrame KeyTime="0" Value="2"/> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="(GrID.Column)" Storyboard.Targetname="Expanderbutton"> <discreteObjectKeyFrame KeyTime="0" Value="1"/> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="(GrID.Row)" Storyboard.Targetname="ExpandSite"> <discreteObjectKeyFrame KeyTime="0" Value="0"/> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Height" Storyboard.Targetname="rd0"> <discreteObjectKeyFrame KeyTime="0" Value="*"/> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="WIDth" Storyboard.Targetname="cd0"> <discreteObjectKeyFrame KeyTime="0" Value="*"/> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState x:name="ExpandRight"> <Storyboard> <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="(GrID.ColumnSpan)" Storyboard.Targetname="Expanderbutton"> <discreteObjectKeyFrame KeyTime="0" Value="1"/> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="(GrID.ColumnSpan)" Storyboard.Targetname="ExpandSite"> <discreteObjectKeyFrame KeyTime="0" Value="1"/> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="(GrID.rowspan)" Storyboard.Targetname="Expanderbutton"> <discreteObjectKeyFrame KeyTime="0" Value="2"/> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="(GrID.rowspan)" Storyboard.Targetname="ExpandSite"> <discreteObjectKeyFrame KeyTime="0" Value="2"/> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="(GrID.Row)" Storyboard.Targetname="ExpandSite"> <discreteObjectKeyFrame KeyTime="0" Value="0"/> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="(GrID.Column)" Storyboard.Targetname="ExpandSite"> <discreteObjectKeyFrame KeyTime="0" Value="1"/> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Height" Storyboard.Targetname="rd0"> <discreteObjectKeyFrame KeyTime="0" Value="*"/> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="WIDth" Storyboard.Targetname="cd1"> <discreteObjectKeyFrame KeyTime="0" Value="*"/> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> </VisualStateGroup> </visualstatemanager.VisualStateGroups> <border x:name="Background" borderBrush="{TemplateBinding borderBrush}" borderThickness="{TemplateBinding borderThickness}" CornerRadius="1,1,1" padding="{TemplateBinding padding}"> <GrID> <GrID.ColumnDeFinitions> <ColumnDeFinition x:name="cd0" WIDth="auto"/> <ColumnDeFinition x:name="cd1" WIDth="auto"/> </GrID.ColumnDeFinitions> <GrID.RowDeFinitions> <RowDeFinition x:name="rd0" Height="auto"/> <RowDeFinition x:name="rd1" Height="auto"/> </GrID.RowDeFinitions> <toolkit:Accordionbutton x:name="Expanderbutton" Background="{TemplateBinding Background}" ContentTemplate="{TemplateBinding headerTemplate}" Content="{TemplateBinding header}" Foreground="{TemplateBinding Foreground}" FontWeight="{TemplateBinding FontWeight}" FontStyle="{TemplateBinding FontStyle}" FontStretch="{TemplateBinding FontStretch}" FontSize="{TemplateBinding FontSize}" FontFamily="{TemplateBinding FontFamily}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" IsTabStop="True" IsChecked="{TemplateBinding IsSelected}" margin="0,0" padding="0,0" GrID.Row="0" Style="{TemplateBinding AccordionbuttonStyle}" VerticalAlignment="{TemplateBinding VerticalAlignment}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/> <ContentControl x:name="ExpandSite" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Foreground="{TemplateBinding Foreground}" FontWeight="{TemplateBinding FontWeight}" FontStyle="{TemplateBinding FontStyle}" FontStretch="{TemplateBinding FontStretch}" FontSize="{TemplateBinding FontSize}" FontFamily="{TemplateBinding FontFamily}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" IsTabStop="False" margin="0,0" GrID.Row="1" Style="{TemplateBinding ExpandableContentControlStyle}" VerticalAlignment="{TemplateBinding VerticalAlignment}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/> </GrID> </border> </GrID> </ControlTemplate> </Setter.Value> </Setter> </Style>
PS.如果要对展开/折叠进行动画处理,您可以在AccordionItem的折叠和展开视觉状态中定义自己的动画.
这真的是一个迟到的答复,希望它可以是任何帮助. 总结
以上是内存溢出为你收集整理的wpf – 如何让手风琴区域(垂直)扩展到动态内容?全部内容,希望文章能够帮你解决wpf – 如何让手风琴区域(垂直)扩展到动态内容?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)