silverlight动态加载模板的例子

silverlight动态加载模板的例子,第1张

概述我在做项目时需要动态添加一些列来显示数据,在网上查找了一些资料,总结了一下,希望对大家有帮助   1.不显示第1列即列指示器(Row Indicators)             在 telerik:RadGridView中设置属性   RowIndicatorVisibility="Collapsed" 2.不显示最上面的分组面板(Group Panel)            在 teler

我在做项目时需要动态添加一些列来显示数据,在网上查找了一些资料,总结了一下,希望对大家有帮助

 

1.不显示第1列即列指示器(Row Indicators)
            在 telerik:RadGrIDVIEw中设置属性   RowIndicatorVisibility="Collapsed"

2.不显示最上面的分组面板(Group Panel)
           在 telerik:RadGrIDVIEw中 设置属性   ShowGroupPanel="False"

3.不显示最左侧的那条线(FroZen Columns Splitter)
           在 telerik:RadGrIDVIEw中 设置属性  CanUserFreezeColumns="False"

4.不显示各表头右侧的过滤按钮(Filter Icon)
            在 telerik:RadGrIDVIEw中设置属性   IsFilteringallowed="False"

5.整体设置GrIDVIEw表头居中
[HTML] vIEw plaincopyprint?<Style targettype="telerik:gridviewheaderCell">  
 <Setter Property="HorizontalContentAlignment"Value="Center"></Setter>   
</Style>  


关键代码
.cs

        private voID Page_Loaded(object sender,RoutedEventArgs e)
        {
            Telerik.windows.Controls.GrIDVIEwColumn oColumn=new Telerik.windows.Controls.GrIDVIEwColumn();
            oColumn.header="标题";
            oColumn.headerTextAlignment=TextAlignment.Center;
            //string strDataTemplate= "<StackPanel Background='{Binding FCaptioncolor}'>\r\n"+
            //                            "<TextBlock Text='{Binding FCaption}'/>\r\n"+
            //                            "</StackPanel>";

//========================动态添加第一列的数据模板========================
            StringBuilder sbTemp = new StringBuilder();
            sbTemp.Append("<DataTemplate ");
            sbTemp.Append("xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' ");
            sbTemp.Append("xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' ");
            sbTemp.Append("xmlns:d='http://schemas.microsoft.com/Expression/blend/2008' ");
            sbTemp.Append("xmlns:mc='http://schemas.openxmlformats.org/markup-compatibility/2006' ");
            //sbTemp.Append("xmlns:navigation='clr-namespace:System.windows.Controls;assembly=System.windows.Controls.Navigation'");
            sbTemp.Append("xmlns:telerik='http://schemas.telerik.com/2008/xaml/presentation' >");
            sbTemp.Append("<StackPanel Background=\"{Binding FCaptioncolor}\">");
            sbTemp.Append("<TextBlock Text=\"{Binding FCaption}\"/>");
            sbTemp.Append("</StackPanel>");          
            sbTemp.Append("</DataTemplate>");
            DataTemplate dtTemplate=(DataTemplate)XamlReader.Load(sbTemp.ToString());
            oColumn.CellTemplate=dtTemplate;
            lstData.Columns.Add(oColumn);
//========================动态添加第二列的数据模板========================
            sbTemp.Remove(0,sbTemp.Length);
            oColumn = new Telerik.windows.Controls.GrIDVIEwColumn();
            oColumn.header = "数据值1";
            oColumn.headerTextAlignment = TextAlignment.Center;
            sbTemp.Append("<DataTemplate ");
            sbTemp.Append("xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' ");
            sbTemp.Append("xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' ");
            sbTemp.Append("xmlns:d='http://schemas.microsoft.com/Expression/blend/2008' ");
            sbTemp.Append("xmlns:mc='http://schemas.openxmlformats.org/markup-compatibility/2006' ");
            //sbTemp.Append("xmlns:navigation='clr-namespace:System.windows.Controls;assembly=System.windows.Controls.Navigation'");
            sbTemp.Append("xmlns:telerik='http://schemas.telerik.com/2008/xaml/presentation' >");
            sbTemp.Append("<StackPanel Background=\"{Binding FValue1color}\">");
            sbTemp.Append("<TextBlock Text=\"{Binding FValue1}\"/>");
            sbTemp.Append("</StackPanel>");
            sbTemp.Append("</DataTemplate>");
            DataTemplate dtTemplate2 = (DataTemplate)XamlReader.Load(sbTemp.ToString());
            oColumn.CellTemplate = dtTemplate2;
            lstData.Columns.Add(oColumn);

            List<FData2> lst = new List<FData2>()
            {
                new FData2{FCaption="标题一",FCaptioncolor="White",FValue1="我的数据1-1",FValue1color="Red"},
                new FData2{FCaption="标题二",FCaptioncolor="Red",FValue1="我的数据2-1",FValue1color="White"},
            };
            lstData.ItemsSource = lst;
        }

    }

    public class FData2
    {
        public string FCaption { get; set; }
        public string FCaptioncolor { get; set; }
        public string FValue1 { get; set; }
        public string FValue1color { get; set; }
        //public string FValue2 { get; set; }
        //public string FValue2color { get; set; }
    }


Xaml代码


<navigation:Page x:Class="SilverlightListVIEw单元格绑定颜色.RadGrIDVIEw动态添加列" 
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
           mc:Ignorable="d"
           xmlns:navigation="clr-namespace:System.windows.Controls;assembly=System.windows.Controls.Navigation"
           d:DesignWIDth="640" d:DesignHeight="480"
           title="RadGrIDVIEw动态添加列 Page" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" Loaded="Page_Loaded">
    <GrID x:name="LayoutRoot" Height="400" WIDth="400" VerticalAlignment="Center" HorizontalAlignment="Center">
        <telerik:RadGrIDVIEw x:name="lstData" Height="211" HorizontalAlignment="left" margin="30,0" VerticalAlignment="top" WIDth="337"  RowIndicatorVisibility="Collapsed" ShowGroupPanel="False" autoGenerateColumns="False" >

        </telerik:RadGrIDVIEw>         <TextBlock Height="21" HorizontalAlignment="left" margin="63,14,0" name="textBlock1" Text="我是在后台代码中动态绑定的" VerticalAlignment="top" WIDth="182" />     </GrID> </navigation:Page>

总结

以上是内存溢出为你收集整理的silverlight动态加载模板的例子全部内容,希望文章能够帮你解决silverlight动态加载模板的例子所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1019220.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存