简体   繁体   English

Silverlight DataGrid Header RotateTransform以编程方式

[英]Silverlight DataGrid Header RotateTransform programmatically

How using rotate transform in code behind to rotate transform header text in DataGrid on Silverlight? 如何在后面的代码中使用旋转变换来旋转Silverlight上的DataGrid中的变换头文本? I don't have conception, but when I try using this code, is not working. 我没有概念,但是当我尝试使用此代码时,它不起作用。

    private DataGridTemplateColumn CreateColumn(int index, string header)
    {
        string cellTemp = string.Format(@"<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" 
            xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
             <CheckBox />
        </DataTemplate>", index);

        DataGridTemplateColumn column = new DataGridTemplateColumn();
        column.Header = header;
        column.CellTemplate = (DataTemplate)XamlReader.Load(cellTemp);

        TransformGroup traGrp = new TransformGroup(){};
        traGrp.Children.Add(new RotateTransform(){ Angle = -35});

        Style transofrm = new Style(typeof(DataGridTemplateColumn));
        transofrm.Setters.Add(new Setter(TextBlock.RenderTransformProperty, traGrp));
        column.HeaderStyle = transofrm;

        return column;
    }

Any idea ? 任何想法 ?

Ok here you go, 好的,你走了,

Add this resource to your user control, 将此资源添加到您的用户控件,

<UserControl.Resources>
        <Style TargetType="sdk:DataGridColumnHeader">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="sdk:DataGridColumnHeader">
                        <Canvas x:Name="RootElement" Height="60" HorizontalAlignment="Stretch">
                            <ContentPresenter Canvas.Left="15" Canvas.Top="50" Content="{TemplateBinding Content}">
                                <ContentPresenter.RenderTransform>
                                    <RotateTransform Angle="-90"/>
                                </ContentPresenter.RenderTransform>
                            </ContentPresenter>
                        </Canvas>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>

and in codebehind.cs do like this, 并在codebehind.cs中这样做,

private DataGridTemplateColumn CreateColumn(int index, string header)
        {
            string cellTemp = string.Format(@"<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" 
            xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
             <CheckBox />
             </DataTemplate>", index);
            DataGridTemplateColumn column = new DataGridTemplateColumn();
            column.Header = header;
            column.HeaderStyle = Resources["Template"] as Style;
            column.CellTemplate = (DataTemplate)XamlReader.Load(cellTemp);


            return column;
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM