mercredi 4 novembre 2015

CheckBox in Grid within ListBox Horizontal Alignment not working

I have a DataGrid where I'm using a RowDetailsTemplate to Display detailed information for the selected DataGrid Item. The information being displayed are something like "SubItems" so I'm using a ListBox with a TextBlock and two CheckBox controls to display all the information.
The controls are positioned using a Grid but I'm not able to center the CheckBox controls within the Grid. They're always left aligned.
I've read several questions on Stackoverflow with similar problems but nothing worked for me. How can I center the two CheckBox controls to the Grid.Column they're assigned to? This is my XAML code:

<DataGrid.RowDetailsTemplate>
<DataTemplate>
    <ListBox Name="lbDependencyDetails" HorizontalContentAlignment="Stretch" ItemsSource="{Binding Path=DependencyView, UpdateSourceTrigger=PropertyChanged}">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Grid HorizontalAlignment="Stretch">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="55" />
                        <ColumnDefinition Width="55" />
                    </Grid.ColumnDefinitions>
                    <TextBlock Grid.Column="0" 
                               Grid.ColumnSpan="2" 
                               Text="{Binding Path=Dependency.SoftwareName}" 
                               Margin="{Binding Path=Margin}" 
                               HorizontalAlignment="Left" />

                    <!--<GridSplitter HorizontalAlignment="Right" Grid.Column="1" Width="2" />-->

                    <CheckBox Grid.Column="2" 
                              IsChecked="{Binding Path=Dependency.IsMarkedForReinstall, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                              HorizontalAlignment="Center" 
                              IsEnabled="False" 
                              Width="55" />
                    <CheckBox Grid.Column="3" 
                              IsChecked="{Binding Path=Dependency.IsMarkedForRepair, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                              HorizontalAlignment="Center" 
                              IsEnabled="False" 
                              Width="55" />
                </Grid>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
</DataTemplate>




Aucun commentaire:

Enregistrer un commentaire