按钮在不同视图中的对齐方式

时间:2022-06-05 23:13:38

I have a userControl with the following xaml which I am reusing in different UserControls. Problem is when there is only one slider visible the orientation of the slider is not center aligned to the slider. But when there are all 4 sliders visible the orientation of the button is center aligned to the slider. Setting margin is not a solution.I tried playing around with containers but no luck. Please help. I have a resource called BRSliderStyle and BRButtonStyle both setting the horizontal and vertical alignments to center for both the controls.

我有一个userControl与以下xaml我在不同的UserControls重用。问题是当只有一个滑块可见时,滑块的方向不与滑块居中对齐。但是当可以看到所有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

1 个解决方案

#1


0  

For example you can use DataTrigger and set Visibility depends on data that you can provide to that trigger.

例如,您可以使用DataTrigger并设置Visibility取决于您可以提供给该触发器的数据。

#1


0  

For example you can use DataTrigger and set Visibility depends on data that you can provide to that trigger.

例如,您可以使用DataTrigger并设置Visibility取决于您可以提供给该触发器的数据。