簡體   English   中英

Center的DataGridCell樣式不起作用

[英]DataGridCell style of Center is not working

<DataGrid.Columns>
    <DataGridTextColumn Header="Id" Binding="{Binding Id, Mode=TwoWay}" IsReadOnly="True" Width="100">
        <DataGridTextColumn.CellStyle>
            <Style>
                <Setter Property="FrameworkElement.HorizontalAlignment" Value="Center"></Setter>
            </Style>
        </DataGridTextColumn.CellStyle>
    </DataGridTextColumn>
    <DataGridTextColumn Header="Name" Binding="{Binding Name, Mode=TwoWay}" IsReadOnly="True" Width="100">
        <DataGridTextColumn.CellStyle>
            <Style>
                <Setter Property="FrameworkElement.HorizontalAlignment" Value="Center"></Setter>
            </Style>
        </DataGridTextColumn.CellStyle>
    </DataGridTextColumn>
    <DataGridTextColumn Header="Group" Binding="{Binding Group, Mode=TwoWay}" IsReadOnly="True" Width="100">
        <DataGridTextColumn.CellStyle>
            <Style>
                <Setter Property="FrameworkElement.HorizontalAlignment" Value="Center"></Setter>
            </Style>
        </DataGridTextColumn.CellStyle>
    </DataGridTextColumn>
</DataGrid.Columns>

我正在嘗試將Center文本標記應用於GridCell,但是它不起作用並且看起來很奇怪。 在此處輸入圖片說明

TextAlignment屬性設置為Center

<DataGridTextColumn Header="Id" Binding="{Binding Id, Mode=TwoWay}" IsReadOnly="True" Width="100">
    <DataGridTextColumn.CellStyle>
        <Style TargetType="DataGridCell">
            <Setter Property="TextBlock.TextAlignment" Value="Center" />
        </Style>
    </DataGridTextColumn.CellStyle>
</DataGridTextColumn>
...

嘗試這個:

 <DataGrid>
        <DataGrid.Columns>
            <DataGridTextColumn>
                <DataGridTextColumn.ElementStyle>
                    <Style TargetType="TextBlock">
                        <Setter Property="TextAlignment" Value="Center" />
                    </Style>
                </DataGridTextColumn.ElementStyle>
            </DataGridTextColumn>
        </DataGrid.Columns>
    </DataGrid>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM