我有一个自定义图形用户控件,我已将它放在堆栈面板中。堆栈面板中最多可以显示4个图形控件。我有复选框来控制图表的可见性。
我遇到的问题是当我取消选中复选框时,堆栈面板中的其余图形不会调整大小以弥补额外的空间。我正在寻找的是当所有图形都可见时它们适合屏幕而不滚动,但如果只有一个图形可见,我希望它的大小可以调整以占用所有空间。
有人有什么想法吗?
这是我到目前为止所做的:
<UniformGrid Grid.Row="2" Name="uniformGrid1" >
<UniformGrid.Resources>
<Utilities:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
</UniformGrid.Resources>
<StackPanel Grid.Row="1" Height="700" Name="graphControls" Orientation="Vertical">
<!--Cross Correlation Graph-->
<View:Graph Width="Auto" Height="Auto" MinHeight="175" Margin="5" x:Name="CrossCorrelationGraph" x:FieldModifier="public"
Visibility="{Binding Path=IsChecked, ElementName=crossCorrelationViewCheck, Converter={StaticResource BooleanToVisibilityConverter}}"
GraphMetadata="{Binding Path=Processor.CrossCorrelation.CrossCorrelationGraphData}"
StartPointAlignment="CenterVertical"
GraphTitle="Cross Correlation"
IsDetailed="True"/>
<!--Power Spectrum Graph-->
<View:Graph Width="Auto" Height="Auto" MinHeight="175" Margin="5" x:Name="PowerSpectrumGraph" x:FieldModifier="public"
Visibility="{Binding Path=IsChecked, ElementName=powerSpectrumViewCheck, Converter={StaticResource BooleanToVisibilityConverter}}"
GraphMetadata="{Binding Path=Processor.CrossCorrelation.PowerSpectrumGraphData}"
StartPointAlignment="Left"
GraphTitle="Power Spectrum"
IsDetailed="True"/>
<!--Phase Spectrum-->
<View:Graph Width="Auto" Height="Auto" MinHeight="175" Margin="5" x:Name="PhaseSpectrum" x:FieldModifier="public"
Visibility="{Binding Path=IsChecked, ElementName=phaseSpectrumViewCheck, Converter={StaticResource BooleanToVisibilityConverter}}"
GraphMetadata="{Binding Path=Processor.CrossCorrelation.PhaseSpectrumGraphData}"
StartPointAlignment="CenterHorizontal"
GraphTitle="Cross Phase Spectrum"
IsDetailed="True"/>
<!--Amplitude Spectrum-->
<View:Graph Width="Auto" Height="Auto" MinHeight="175" Margin="5" x:Name="AmplitudeSpectrumGraph" x:FieldModifier="public"
Visibility="{Binding Path=IsChecked, ElementName=amplitudeSpectrumViewCheck, Converter={StaticResource BooleanToVisibilityConverter}}"
StartPointAlignment="Left"
GraphTitle="Cross Amplitude Spectrum"
IsDetailed="True"/>
</StackPanel>
</UniformGrid>
答案 0 :(得分:1)
玩了一会儿之后我找到了解决办法。我会在这里发布,以便其他人可以受益。
首先,我放弃了堆栈面板,并使用了UniformGrid。我将UniformGrid上的columns属性设置为1,因此所有内容都将一行排在另一行之上。一切都很好。
<UniformGrid Grid.Row="2" Height="Auto" Columns="1">
<UniformGrid.Resources>
<Utilities:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
</UniformGrid.Resources>
<!--Cross Correlation Graph-->
<View:Graph Width="Auto" Height="Auto" MinHeight="175" Margin="5" x:Name="CrossCorrelationGraph" x:FieldModifier="public"
Visibility="{Binding Path=IsChecked, ElementName=crossCorrelationViewCheck, Converter={StaticResource BooleanToVisibilityConverter}}"
GraphMetadata="{Binding Path=Processor.CrossCorrelation.CrossCorrelationGraphData}"
StartPointAlignment="CenterVertical"
GraphTitle="Cross Correlation"
IsDetailed="True"/>
<!--Power Spectrum Graph-->
<View:Graph Width="Auto" Height="Auto" MinHeight="175" Margin="5" x:Name="PowerSpectrumGraph" x:FieldModifier="public"
Visibility="{Binding Path=IsChecked, ElementName=powerSpectrumViewCheck, Converter={StaticResource BooleanToVisibilityConverter}}"
GraphMetadata="{Binding Path=Processor.CrossCorrelation.PowerSpectrumGraphData}"
StartPointAlignment="Left"
GraphTitle="Power Spectrum"
IsDetailed="True"/>
<!--Phase Spectrum-->
<View:Graph Width="Auto" Height="Auto" MinHeight="175" Margin="5" x:Name="PhaseSpectrum" x:FieldModifier="public"
Visibility="{Binding Path=IsChecked, ElementName=phaseSpectrumViewCheck, Converter={StaticResource BooleanToVisibilityConverter}}"
GraphMetadata="{Binding Path=Processor.CrossCorrelation.PhaseSpectrumGraphData}"
StartPointAlignment="CenterHorizontal"
GraphTitle="Cross Phase Spectrum"
IsDetailed="True"/>
<!--Amplitude Spectrum-->
<View:Graph Width="Auto" Height="Auto" MinHeight="175" Margin="5" x:Name="AmplitudeSpectrumGraph" x:FieldModifier="public"
Visibility="{Binding Path=IsChecked, ElementName=amplitudeSpectrumViewCheck, Converter={StaticResource BooleanToVisibilityConverter}}"
StartPointAlignment="Left"
GraphTitle="Cross Amplitude Spectrum"
IsDetailed="True"/>
</UniformGrid>