【发布时间】:2017-09-29 01:13:55
【问题描述】:
我有一个带有以下 xaml 的 userControl,我在不同的 UserControl 中重用了它。问题是当只有一个滑块可见时,滑块的方向未与滑块中心对齐。但是当所有 4 个滑块都可见时,按钮的方向与滑块中心对齐。设置边距不是解决方案。我尝试使用容器但没有运气。请帮忙。我有一个名为 BRSliderStyle 和 BRButtonStyle 的资源,它们都将水平和垂直对齐方式设置为两个控件的中心。
<UserControl>
<UserControl.Resources>
<BooleanToVisibilityConverter
x:Key="visibleConverter"></BooleanToVisibilityConverter>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition
Height="*"></RowDefinition>
<RowDefinition
Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<StackPanel
Orientation="Vertical" Grid.Row="0"
DockPanel.Dock="Top">
<helper:BRSliderUserControl
x:Name="ChartAxisSliderControl"
SliderValuesDictionary="{Binding m_ChartAxisLabelTextSizeSliderAssociatedDictionary,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type UserControl}}}"
DefaultSliderValue="{Binding m_ChartAxisTextSizeSliderDefaultValue,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type UserControl}}}"
AnalysisType="{Binding AnalysisTypeValue,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type UserControl}}}"
ChartAssociatedProperty="{x:Static dd:ChartAssociatedProperties.ChartAxisLabelsTextSize}"
SessionIdProperty="{Binding SessionIdProperty,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type UserControl}}}"
Visibility="{Binding Path=DataContext.ShowChartAxisSlider,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type UserControl}},Converter={StaticResource visibleConverter}}"></helper:BRSliderUserControl>
<helper:BRSliderUserControl
x:Name="ChartMarkerSliderControl"
Margin="0,20,0,0"
SliderValuesDictionary="{Binding m_ChartMarkerSizeSliderAssociatedDictionary,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type UserControl}}}"
DefaultSliderValue="{Binding m_ChartMarkerSizeSliderDefaultValue,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type UserControl}}}"
AnalysisType="{Binding AnalysisTypeValue,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type UserControl}}}"
ChartAssociatedProperty="{x:Static dd:ChartAssociatedProperties.ChartMarkersSize}"
SessionIdProperty="{Binding SessionIdProperty,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type UserControl}}}"
Visibility="{Binding Path= DataContext.ShowChartMarkerSlider,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type UserControl}},Converter={StaticResource visibleConverter}}"></helper:BRSliderUserControl>
<helper:BRSliderUserControl
x:Name="ChartDataLabelSliderControl"
Margin="0,20,0,0"
SliderValuesDictionary="{Binding m_ChartDataLabelTextSizeSliderAssociatedDictionary,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type UserControl}}}"
DefaultSliderValue="{Binding m_ChartDataLabelTextSizeSliderDefaultValue,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type UserControl}}}"
AnalysisType="{Binding AnalysisTypeValue,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type UserControl}}}"
ChartAssociatedProperty="{x:Static dd:ChartAssociatedProperties.ChartDataLabelsTextSize}"
SessionIdProperty="{Binding SessionIdProperty,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type UserControl}}}"
Visibility="{Binding Path=DataContext.ShowChartDataLabelSlider,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type UserControl}},Converter={StaticResource visibleConverter}}"></helper:BRSliderUserControl>
<helper:BRSliderUserControl
x:Name="ChartUpDownSliderControl"
Margin="0,20,0,0"
SliderValuesDictionary="{Binding m_ChartDataLabelPlacementSliderAssociatedDictionary,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type UserControl}}}"
DefaultSliderValue="{Binding m_ChartDataLabelPlacementSliderDefaultValue,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type UserControl}}}"
AnalysisType="{Binding AnalysisTypeValue,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type UserControl}}}"
ChartAssociatedProperty="{x:Static dd:ChartAssociatedProperties.ChartDataLabelsPlacementTopOrBottom}"
SessionIdProperty="{Binding SessionIdProperty,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type UserControl}}}"
Visibility="{Binding Path=DataContext.ShowChartUpOrDownSlider,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type UserControl}},Converter={StaticResource visibleConverter}}"></helper:BRSliderUserControl>
</StackPanel>
<StackPanel
Grid.Row="1"
HorizontalAlignment="Center" Margin="0,20,0,0">
<Button
x:Name="SaveDefaultSettings"
Content="{StaticResource SaveAsDefault}"
Click="SaveDefaultSettings_Click"
Width="180"></Button>
</StackPanel>
</Grid>
</UserControl
【问题讨论】:
-
我不太明白你的问题。您可以添加一些屏幕截图来显示您想要实现的目标吗?