Member 14079295 Ответов: 1

Проблема проектирования Datagridview и проблема положения контента


У меня есть DataGridView в моем проекте, и я настраиваю некоторые его функции, но у меня есть проблема, и моя проблема заключается в том, что я не могу установить содержимое ячеек в центральное положение.
( на самом деле мне нужен шаблон темной темы для datagridview в wpf c# )

Что я уже пробовал:

<DataGrid x:Name="UsersInfoDataGridView" Grid.Column="0" Grid.Row="2" Width="800" Height="180" FlowDirection="RightToLeft" AutoGenerateColumns="False" BorderBrush="Transparent" Background="#FF4A4A4A" Foreground="White" HorizontalGridLinesBrush="#F6F7F9" VerticalGridLinesBrush="Transparent" VerticalAlignment="Center" HorizontalAlignment="Center" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" RowHeaderWidth="10" RowHeight="30" RowBackground="#FF4A4A4A" Padding="5" AlternatingRowBackground="#FF4A4A4A">
                    <DataGrid.Columns>
                        <DataGridTextColumn Width="200" Header="نام و نام خانوادگی کاربر" Binding="{Binding UsersFullName}">
                            <DataGridTextColumn.HeaderStyle>
                                <Style TargetType="DataGridColumnHeader">
                                    <Setter Property="Background" Value="#333333"/>
                                    <Setter Property="Foreground" Value="White"/>
                                    <Setter Property="VerticalContentAlignment" Value="Center"/>
                                    <Setter Property="HorizontalContentAlignment" Value="Center"/>
                                    <Setter Property="VerticalAlignment" Value="Center"/>
                                    <Setter Property="HorizontalAlignment" Value="Center"/>
                                    <Setter Property="Width" Value="200"/>
                                    <Setter Property="Height" Value="40"/>
                                    <Setter Property="FontFamily" Value="Tahoma"/>
                                    <Setter Property="FontSize" Value="15"/>
                                </Style>
                            </DataGridTextColumn.HeaderStyle>
                            <DataGridTextColumn.ElementStyle>
                                <Style TargetType="{x:Type TextBlock}">
                                    <Setter Property="Background" Value="#FF4A4A4A"/>
                                    <Setter Property="Foreground" Value="White"/>
                                    <Setter Property="VerticalAlignment" Value="Center"/>
                                    <Setter Property="HorizontalAlignment" Value="Center"/>
                                    <Setter Property="Width" Value="200"/>
                                    <Setter Property="Height" Value="30"/>
                                    <Setter Property="FontFamily" Value="Tahoma"/>
                                    <Setter Property="FontSize" Value="15"/>
                                </Style>
                            </DataGridTextColumn.ElementStyle>
                        </DataGridTextColumn>
                        <DataGridTextColumn Width="200" Header="شماره تلفن" Binding="{Binding PhoneNumberD}">
                            <DataGridTextColumn.HeaderStyle>
                                <Style TargetType="DataGridColumnHeader">
                                    <Setter Property="Background" Value="#333333"/>
                                    <Setter Property="Foreground" Value="White"/>
                                    <Setter Property="VerticalContentAlignment" Value="Center"/>
                                    <Setter Property="HorizontalContentAlignment" Value="Center"/>
                                    <Setter Property="VerticalAlignment" Value="Center"/>
                                    <Setter Property="HorizontalAlignment" Value="Center"/>
                                    <Setter Property="Width" Value="200"/>
                                    <Setter Property="Height" Value="40"/>
                                    <Setter Property="FontFamily" Value="Tahoma"/>
                                    <Setter Property="FontSize" Value="15"/>
                                </Style>
                            </DataGridTextColumn.HeaderStyle>
                            <DataGridTextColumn.ElementStyle>
                                <Style TargetType="{x:Type TextBlock}">
                                    <Setter Property="Background" Value="#FF4A4A4A"/>
                                    <Setter Property="Foreground" Value="White"/>
                                    <Setter Property="VerticalAlignment" Value="Center"/>
                                    <Setter Property="HorizontalAlignment" Value="Center"/>
                                    <Setter Property="Width" Value="200"/>
                                    <Setter Property="Height" Value="30"/>
                                    <Setter Property="FontFamily" Value="Tahoma"/>
                                    <Setter Property="FontSize" Value="15"/>
                                </Style>
                            </DataGridTextColumn.ElementStyle>
                        </DataGridTextColumn>
                        <DataGridTextColumn Width="200" Header="ایمیل کاربر" Binding="{Binding EmailAddressD}">
                            <DataGridTextColumn.HeaderStyle>
                                <Style TargetType="DataGridColumnHeader">
                                    <Setter Property="Background" Value="#333333"/>
                                    <Setter Property="Foreground" Value="White"/>
                                    <Setter Property="VerticalContentAlignment" Value="Center"/>
                                    <Setter Property="HorizontalContentAlignment" Value="Center"/>
                                    <Setter Property="VerticalAlignment" Value="Center"/>
                                    <Setter Property="HorizontalAlignment" Value="Center"/>
                                    <Setter Property="Width" Value="200"/>
                                    <Setter Property="Height" Value="40"/>
                                    <Setter Property="FontFamily" Value="Tahoma"/>
                                    <Setter Property="FontSize" Value="15"/>
                                </Style>
                            </DataGridTextColumn.HeaderStyle>
                            <DataGridTextColumn.ElementStyle>
                                <Style TargetType="{x:Type TextBlock}">
                                    <Setter Property="Background" Value="#FF4A4A4A"/>
                                    <Setter Property="Foreground" Value="White"/>
                                    <Setter Property="VerticalAlignment" Value="Center"/>
                                    <Setter Property="HorizontalAlignment" Value="Center"/>
                                    <Setter Property="Width" Value="200"/>
                                    <Setter Property="Height" Value="30"/>
                                    <Setter Property="FontFamily" Value="Tahoma"/>
                                    <Setter Property="FontSize" Value="15"/>
                                </Style>
                            </DataGridTextColumn.ElementStyle>
                        </DataGridTextColumn>
                        <DataGridTextColumn Width="200" Header="نام کاربری کاربر" Binding="{Binding UserNameD}">
                            <DataGridTextColumn.HeaderStyle>
                                <Style TargetType="DataGridColumnHeader">
                                    <Setter Property="Background" Value="#333333"/>
                                    <Setter Property="Foreground" Value="White"/>
                                    <Setter Property="VerticalContentAlignment" Value="Center"/>
                                    <Setter Property="HorizontalContentAlignment" Value="Center"/>
                                    <Setter Property="VerticalAlignment" Value="Center"/>
                                    <Setter Property="HorizontalAlignment" Value="Center"/>
                                    <Setter Property="Width" Value="200"/>
                                    <Setter Property="Height" Value="40"/>
                                    <Setter Property="FontFamily" Value="Tahoma"/>
                                    <Setter Property="FontSize" Value="15"/>
                                </Style>
                            </DataGridTextColumn.HeaderStyle>
                            <DataGridTextColumn.ElementStyle>
                                <Style TargetType="{x:Type TextBlock}">
                                    <Setter Property="Background" Value="#FF4A4A4A"/>
                                    <Setter Property="Foreground" Value="White"/>
                                    <Setter Property="VerticalAlignment" Value="Center"/>
                                    <Setter Property="HorizontalAlignment" Value="Center"/>
                                    <Setter Property="Width" Value="200"/>
                                    <Setter Property="Height" Value="30"/>
                                    <Setter Property="FontFamily" Value="Tahoma"/>
                                    <Setter Property="FontSize" Value="15"/>
                                </Style>
                            </DataGridTextColumn.ElementStyle>
                        </DataGridTextColumn>
                    </DataGrid.Columns>
                </DataGrid>

1 Ответов

Рейтинг:
2

Gerry Schmitz

Есть еще одно свойство "выравнивания", связанное с фактическим "текстом" по сравнению с размещением "элемента управления".

...TextAlignment = TextAlignment.Center;