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

时间:2017-09-29 01:13:55

标签: wpf xaml

我有一个带有以下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

1 个答案:

答案 0 :(得分:0)

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