开发者

Using multiple LayoutTransforms in one Control (Grid View Header) in WPF

I am trying to build a grid of items, all dynamically (rows and columns) generated. I have a listview and gridview. I get all of the columns, and add them to the gridview. I then add all my rows to a table, and bind that to the listview.

I am using something similar to rotate the header names on the top of the view.

                    <ListView Name="lvEverything">
                    <ListView.Resources>
                        <Style TargetType="{x:Type GridViewColumnHeader}">
                            <Setter Property="LayoutTransform">
                                <Setter.Value>
                                    <RotateTransform Angle="-90"/>
                                </Setter.Value>
                            </Setter>
                            <Setter Property="Width" Value="250"></Setter>
                        </Style>
                    </ListView.Resources>

This works fine, it rotates the text and makes the columns the right size fo开发者_JAVA百科r now.

What I would like to do though, it set the first column to NOT rotate. I am not sure and can not get it to only apply this to the columns I want it to.


Set the HeaderContainerStyle on the first column explicitly so it will not fall back to using the implicit one:

<ListView Name="lvEverything">
    <ListView.Resources>
        <Style TargetType="{x:Type GridViewColumnHeader}">
            <Setter Property="LayoutTransform">
                <Setter.Value>
                    <RotateTransform Angle="-90"/>
                </Setter.Value>
            </Setter>
            <Setter Property="Width" Value="250"></Setter>
        </Style>
        <Style x:Key="FirstColumnStyle" TargetType="GridViewColumnHeader"/>
    </ListView.Resources>
    <ListView.View>
        <GridView>
            <GridViewColumn Header="First Column"
                DisplayMemberBinding="{Binding FirstColumn}"
                HeaderContainerStyle="{StaticResource FirstColumnStyle}"/>
            <GridViewColumn Header="Second Column"
                DisplayMemberBinding="{Binding SecondColumn}"/>
        </GridView>
    </ListView.View>
</ListView>

Or, if you are creating the columns in code:

GridViewColumn firstColumn = ...;
firstColumn.HeaderContainerStyle = new Style();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜