WPF: выравнивание последних ДВУХ элементов управления в StackPanel / DockPanel с правой стороны - PullRequest
4 голосов
/ 24 октября 2010

Это мой код, который до сих пор не работает:

   <DockPanel  >        
            <Button Content="Start" Command="{Binding Path=FirstDateCommand}" />
            <Button Content="Back"  Command="{Binding Path=PreviousDateCommand}" />          
            <DatePicker Width="150"
                SelectedDate="{Binding Path=SelectedDate}"
                DisplayDateStart="{Binding Path=MinDate}" 
                DisplayDateEnd="{Binding Path=MaxDate}" SelectedDateFormat="Long" />
            <Button Content="Forward" Command="{Binding Path=NextDateCommand}" />
            <Button Content="End"     Command="{Binding Path=LastDateCommand}" />

            <Button Command="{Binding PrintCommand}" Content="Print Planner" />
            <Button Command="{Binding ToggleDocumentsCommand}" Content="Show Docs"  />
            <Button Command="{Binding MaterialExplorerShowCommand}" Content="Browse Docs" />
            <Button Command="{Binding LessonPlannerCommand}" Content="Edit Planner" />
            <TextBox Text="{Binding SearchText,Mode=TwoWay}" Width="50" />          
            <Button Command="{Binding FindAllCommand}" Content="Search"  />

            <DockPanel DockPanel.Dock="Right" HorizontalAlignment="Right">
                <TextBlock Text="class code:" VerticalAlignment="Center" />
                <ComboBox 
                ItemsSource="{Binding GroupViewModelList}" 
                Style="{StaticResource GroupViewModelStyle}"
                ItemTemplate="{StaticResource GroupViewModelItemTemplate}" 
                Width="100"/>
            </DockPanel>

        </DockPanel>

alt text

Как я могу установить 2 последних элемента управления на изображении с самой правой стороны?

ОБНОВЛЕНИЕ :

<Grid  Name="MainGrid">
        <Grid.RowDefinitions>
            <RowDefinition Height="40" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid Margin="10,10,10,0"  Grid.Row="0" Name="ButtonBar">
            <StackPanel FocusManager.IsFocusScope="True" Orientation="Horizontal">               
                <ComboBox  
                        AlternationCount="2"
                        FontSize="16"
                        VerticalContentAlignment="Center"
                        Width="100" 
                        ItemContainerStyle="{StaticResource alternateColor}" 
                        ItemsSource="{Binding Source={x:Static Member=Fonts.SystemFontFamilies}}" x:Name="fontComboFast">
                    <ComboBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <VirtualizingStackPanel VirtualizingStackPanel.VirtualizationMode="Recycling" />
                        </ItemsPanelTemplate>
                    </ComboBox.ItemsPanel>                    
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Width="100" Text="{Binding}" FontFamily="{Binding }" />
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>

                <!--<View:FormatButtonBar />-->
                <View:DateNavigatorView />
                <View:LessonPlannerView />
                <!--<View:TextFormatBarUC />-->
            </StackPanel>
        </Grid>

2 элемента управления находятся в LessonPlannerView (UserControl)

Внутри LessonPlannerView вы найдете этот код:

...
    <Grid >
        <DockPanel>              
            <Button Command="{Binding PrintCommand}" Content="Print Planner" />
            <Button Command="{Binding ToggleDocumentsCommand}" Content="Show Docs"  />
            <Button Command="{Binding MaterialExplorerShowCommand}" Content="Browse Docs" />
            <Button Command="{Binding LessonPlannerCommand}" Content="Edit Planner" />
            <TextBox Text="{Binding SearchText,Mode=TwoWay}" Width="50" />          
            <Button Command="{Binding FindAllCommand}" Content="Search"  />            
            <StackPanel x:Name="ClassCodeChooser" Orientation="Horizontal" DockPanel.Dock="Right" HorizontalAlignment="Right">
                <TextBlock Text="class code:" VerticalAlignment="Center" />
                <ComboBox ItemsSource="{Binding SchoolclassCodeList}"                 
                />
        </StackPanel>            
        </DockPanel>
    </Grid>
</UserControl>

1 Ответ

2 голосов
/ 24 октября 2010

Это должно быть хорошо, но вам действительно не нужны вложенные DockPanel. Вы можете изменить внутреннюю панель DockPanel на горизонтальную панель StackPanel.

Но настоящая проблема в том, что ваша внешняя DockPanel, кажется, не расширяется на всю ширину своего контейнера. Установите фон на внешнюю панель DockPanel, чтобы получить визуальное представление о том, почему он не заполняет свой контейнер.

В ответ на ветку комментариев ниже, добавив следующий пример

<Grid Name="ButtonBar">
    <Grid.RowDefinitions>
        <RowDefinition Height="40" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>

    <DockPanel Grid.Row="0">
        <View:FormatButtonBar />  <!-- this will dock left -->
        <View:DateNavigatorView />  <!-- this will dock left -->
        <View:LessonPlannerView />  <!-- this will dock left -->
        <View:TextFormatBarUC /> <!-- this will fill -->
    </DockPanel>

</Grid>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...