找回密码
 立即注册

QQ登录

只需一步,快速开始

heyixiaoran

论坛元老

6

主题

26

帖子

9032

积分

论坛元老

积分
9032

活字格认证微信认证勋章元老葡萄

heyixiaoran
论坛元老   /  发表于:2014-12-1 23:04  /   查看:4895  /  回复:3
C1FlexGrid 设置HeaderBackground 后,一旦点击排序或者左上角的全部选择等,颜色会失去,请问需要在哪个事件里重新设置颜色呢?

3 个回复

倒序浏览
Alice
社区贡献组   /  发表于:2014-12-2 10:34:00
沙发
回复 1楼heyixiaoran的帖子

有关颜色失去,推测是因为被选择后,使用了选择的背景色。
你能将Demo或是相关代码发给我们看看么?
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
heyixiaoran
论坛元老   /  发表于:2014-12-2 14:57:00
板凳






public static class C1FlexGridExtensions
    {
        public static ObservableCollection<ColumnConfig> GetBindingColumns(DependencyObject obj)
        {
            return (ObservableCollection<ColumnConfig>)obj.GetValue(BindingColumnsProperty);
        }

        public static void SetBindingColumns(DependencyObject obj, ObservableCollection<ColumnConfig> value)
        {
            obj.SetValue(BindingColumnsProperty, value);
        }

        // Using a DependencyProperty as the backing store for BindingColumns.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty BindingColumnsProperty =
            DependencyProperty.RegisterAttached("BindingColumns", typeof(ObservableCollection<ColumnConfig>), typeof(C1FlexGridExtensions), new PropertyMetadata(null, BindingColumnsChanged));

        private static void BindingColumnsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var bindingColumns = e.NewValue as ObservableCollection<ColumnConfig>;
            if (bindingColumns != null)
            {
                var c1FlexGrid = d as C1FlexGrid;
                if (c1FlexGrid != null)
                {
                    foreach (var bindingColumn in bindingColumns)
                    {

                        c1FlexGrid.Columns.Add(new Column
                        {
                            Header = bindingColumn.HeaderName,
                            Binding = new Binding(bindingColumn.ColumnName),
                            Width = new GridLength(bindingColumn.Width),
                            Format = bindingColumn.FormatString,
                            HeaderBackground = new SolidColorBrush(ColorConverter.ConvertFromString(bindingColumn.ColorString) is Color ? (Color) ColorConverter.ConvertFromString(bindingColumn.ColorString) : Colors.White)
                        });
                    }
                }
            }
        }

我是这样绑定的,然后显示


点击列名排序后,再让列名失去焦点

颜色消失了

或者点击左上角,行头和列头交叉的那个方块也会失去颜色

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2014-12-2 18:41:00
地板
回复 3楼heyixiaoran的帖子

你好,我进行了如下的测试,在XMAL里,将HeaderBackground设置为红色。没有重现你的问题,运行时selected header依然是红色。
如下是我测试代码:
  1.         <c1:C1FlexGrid Name="c1FlexGrid1" AutoGenerateColumns="False" Grid.Row="1">
  2.             <c1:C1FlexGrid.Columns>
  3.                 <c1:Column HeaderBackground="Red" Binding="{Binding ID}" Header="ID" Width="50"/>
  4.                 <c1:Column HeaderBackground="Red" Binding="{Binding FName}" Header="First Name" Width="200">
  5.                     <c1:Column.CellTemplate>
  6.                         <DataTemplate>
  7.                             <TextBlock Text="{Binding FName}"/>
  8.                         </DataTemplate>
  9.                     </c1:Column.CellTemplate>
  10.                 </c1:Column>
  11.                 <c1:Column HeaderBackground="Red" Binding="{Binding LName}" Header="Last Name" Width="200"/>
  12.             </c1:C1FlexGrid.Columns>
  13.         </c1:C1FlexGrid>
复制代码


推测是你的代码中某部分影响到了Headerbackground。请检查相关代码。
我的测试Demo:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部