GridView控件右对齐CellTemplate控件、右对齐、GridView、CellTemplate

2023-09-04 03:43:44 作者:M16-穿云箭

我如何将TextBlock是右对齐

 < GridViewColumn WIDTH =45>
    < GridViewColumnHeader CONTENT =#督Horizo​​ntalContentAlignment =左/>
    < GridViewColumn.CellTemplate>
        <的DataTemplate>
            < TextBlock的TextWrapping =NoWrap的TextAlignment =右的Horizo​​ntalAlignment =右
                文本={绑定路径=伯爵的StringFormat = {} {0:N0},模式=单向}/>
        < / DataTemplate中>
    < /GridViewColumn.CellTemplate>
< / GridViewColumn>
 

Horizo​​ntalContentAlignment和TextAlignment不解决它(对我来说)

甚至尝试,并没有解决它(对我来说)

 < ListView.Resources>
    <风格的TargetType =ListViewItem的>
        < setter属性=Horizo​​ntalContentAlignmentVALUE =右/>
    < /样式和GT;
< /ListView.Resources>
 

解决方案

有一个看看这里:

的http://highfieldtales.word$p$pss.com/2013/11/10/hacking-the-wpf-gridview-two-more-features/

这是一个系列的职位按我如何破解GridView控件,并得到一些隐藏的宝石从它。

在ASP.NET 2.0中操作数据之十二 在GridView控件中使用TemplateField

How do I get the TextBlock to be Right aligned

<GridViewColumn Width="45">
    <GridViewColumnHeader Content="#Doc" HorizontalContentAlignment="Left"/>
    <GridViewColumn.CellTemplate>
        <DataTemplate>
            <TextBlock TextWrapping="NoWrap"  TextAlignment="Right" HorizontalAlignment="Right"
                Text="{Binding Path=Count, StringFormat={}{0:N0}, Mode=OneWay}"/>
        </DataTemplate>
    </GridViewColumn.CellTemplate>
</GridViewColumn>

HorizontalContentAlignment and TextAlignment don't fix it (for me)

even tried and it did not fix it (for me)

<ListView.Resources>  
    <Style TargetType="ListViewItem">  
        <Setter Property="HorizontalContentAlignment" Value="Right" />  
    </Style>
</ListView.Resources>  

解决方案

Have a look here:

http://highfieldtales.wordpress.com/2013/11/10/hacking-the-wpf-gridview-two-more-features/

It's a series of posts by me on how to hack the GridView, and get some hidden gem from it.