1
Vote

DataGrid RowHeader not visible

description

I have currently set a project where DataGridRow Headers need to bound like so.
 <TextBlock   Text="{Binding Path=DataContext.RowHeader, RelativeSource={RelativeSource AncestorType=DataGrid}}" Foreground="Black" />
They show up on a normal XAML project but when I change it to an Elysium project, it does not render the visual control but sets binding correctly ( verified via Snoop)
Please help me rectify this problem. Thanks in advance. Full code attached:
<extra:Window x:Class="DI.Autofac.WPF.Views.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:extra="http://schemas.extra.com/ui" 
    xmlns:params="http://schemas.codeplex.com/elysium/params"
              
        Title="Window1" Height="300" Width="300">
    <Window.Resources>
        
       
    </Window.Resources>
    <Grid>
        <DataGrid x:Name="DataGrid1" AutoGenerateColumns="False" ItemsSource="{Binding Results}" Loaded="Try"  SelectionUnit="Cell" ToolTip="{StaticResource ABC}">
                <DataGrid.RowHeaderTemplate>
                <DataTemplate DataType="{x:Type DataGridRow}" >
                    <TextBlock   Text="{Binding Path=DataContext.RowHeader, RelativeSource={RelativeSource AncestorType=DataGrid}}" Foreground="Black" />
                </DataTemplate>
                </DataGrid.RowHeaderTemplate>
            
           
        </DataGrid>
        
    </Grid>
</extra:Window>
public partial class Window1 
    {
       
       public IEnumerable<dynamic> Results { get; set; }
        public Window1()
        {
            InitializeComponent();
            DataGrid1.DataContext = (this);
            string A = "-,1m,1y,0.2,2y,1.3|-,2m,1y,0.2,2y,1.3|-,3m,1y,0.2,2y,1.3";
            DataGrid1.HeadersVisibility = DataGridHeadersVisibility.All;
            this.Results = GenerateDataGridObjects(A);
            
            
            
            

        }

     
        public  IEnumerable<dynamic> GenerateDataGridObjects(string input)
        {
            ICollection<dynamic> output = new Collection<dynamic>();
            string[] firstparse = input.Split('|');
            foreach (string row in firstparse)
            {
                dynamic dynamo = new ExpandoObject();
                string[] properties = row.Split(',');
                var dictdynamo = dynamo as IDictionary<string, object>;
                Queue<string> propertiesloaded = new Queue<string>();
                foreach (string property in properties)
                {
                    propertiesloaded.Enqueue(property);
                   
                }
                int i = 0;
                while (!(propertiesloaded.Count == 0))
                {
                    var Key = propertiesloaded.Dequeue();
                    var Value = propertiesloaded.Dequeue();
                    if( i ==0)
                    {
                         dynamo.RowHeader = Value;
                         i++;
                    }
                   
                    dictdynamo[Key] = Value;
                   
                }
           
                output.Add(dynamo);
                
                }
            return output;
            
        }

        private void Try(object sender, RoutedEventArgs e)
        {
                var rows = DataGrid1.ItemsSource.OfType<IDictionary<string, object>>();
                var columns = rows.SelectMany(d => d.Keys).Distinct(StringComparer.OrdinalIgnoreCase);
                int i =0;
                foreach (string text in columns)
                {

                
                    {
                        var column = new DataGridTextColumn
                        {
                            Header = text,
                            Binding = new Binding(text),
                        
                        };
                        if (i==0 | i==1)
                        {
                            column.Visibility = System.Windows.Visibility.Hidden;
                            i++;
                        }
                        if (i != 0 && i!=1)
                        {
                            DataGrid1.Columns.Add(column);
                        }
                   
                    }

                
                }

        }
    }

comments