Click here to Skip to main content
15,890,123 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: speed up Silverlight project Pin
Pete O'Hanlon2-Jul-13 23:28
mvePete O'Hanlon2-Jul-13 23:28 
Questioncan we get audio buffer in mediaelement. Pin
brodcasting2-Jul-13 0:50
brodcasting2-Jul-13 0:50 
QuestionDrawing Lines Dynamically Pin
velkumar_in30-Jun-13 23:44
velkumar_in30-Jun-13 23:44 
QuestionRe: Drawing Lines Dynamically Pin
Kenneth Haugland5-Jul-13 14:05
mvaKenneth Haugland5-Jul-13 14:05 
QuestionGridView click to load data Pin
maxRazar27-Jun-13 22:00
maxRazar27-Jun-13 22:00 
Questionhow to get audiometer level in mediaelement Pin
brodcasting27-Jun-13 19:13
brodcasting27-Jun-13 19:13 
QuestionRe: how to get audiometer level in mediaelement Pin
Kenneth Haugland5-Jul-13 14:06
mvaKenneth Haugland5-Jul-13 14:06 
Questiondatagrid columns, ExpandoObject question Pin
BoydMills27-Jun-13 9:07
BoydMills27-Jun-13 9:07 
I am trying to create a reasonably complex datagrid.
At the core, there are sting pairs where the first string is the key and the second is the value.

I make 2 passes through the base array. Don't try to understand the base array, just accept that 2 strings, key and value, are extracted.

On the first pass, the datagrid has columns dynamically created. The column names works as expected. I believe the binding is not correct.

Once all know possible columns are known, the second pass extracts the key/value pairs from the original table and composes a dictionary called "person".

The original table is a 2 dimensional table, first an array of key/values of dynamic length then a dynamic number of such arrays.

Each dictionary is added to a List called "persons"

If a particular key is not found in the base table, the value "_" is assigned.

Finally the datagrid.itemsource is assigned the list "persons".



When the datagrid is displayed, the column names are correct.
The number of columns is correct.
The number of rows is correct but blank.

The debugger output window shows a flurry of error messages such as:

==========
System.Windows.Data Error: BindingExpression path error: 'mv' property not found on 'System.Dynamic.ExpandoObject' 'System.Dynamic.ExpandoObject' (HashCode=60469192). BindingExpression: Path='mv' DataItem='System.Dynamic.ExpandoObject' (HashCode=60469192); target element is 'System.Windows.Controls.TextBlock' (Name=''); target property is 'Text' (type 'System.String')...


======

Note that "mv" is one of the column names.
When I display the "persons" list using the debugger dynamicview for "persons" it does show the column name "mv" with the correct value.

The xaml:
===
XML
<controls:ChildWindow x:Class="VCI_Envision_Portal.Views.LegacyGraphicDisplay.BackgroundDataxaml"
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
           xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
           xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
           Width="400" Height="300"
           Title="BackgroundDataxaml"
           xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
           >
    <Grid x:Name="LayoutRoot" Margin="2">
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <Button x:Name="CancelButton" Content="Cancel" Click="CancelButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,0,0" Grid.Row="1" />
        <Button x:Name="OKButton" Content="OK" Click="OKButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,79,0" Grid.Row="1" />
        <data:DataGrid AutoGenerateColumns="True"  Height="226" HorizontalAlignment="Left" Name="BackgroundDataGrid" VerticalAlignment="Top" Width="372" />
    </Grid>
</controls:ChildWindow>



===

the xaml.cs:
====
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections;
using System.Collections.ObjectModel;
using System.Windows.Data;
using System.Dynamic;
using Microsoft.CSharp;
using Microsoft.CSharp.RuntimeBinder;

using VCI_Envision_Portal.VCIWCFServicesNS;

namespace VCI_Envision_Portal.Views.LegacyGraphicDisplay
{
    public partial class BackgroundDataxaml : ChildWindow
    {
        private ObservableCollection<VCI_Point_Data[]> vci_pt_data_cooked_bg = new ObservableCollection<VCI_Point_Data[]>();
        List< ExpandoObject  > persons;

        public BackgroundDataxaml(VCI_Point_Data[][] vci_pt_data_cooked_in)
        {
            int i;
            for (i = 0; i < vci_pt_data_cooked_in.Length; i++)
            {
                vci_pt_data_cooked_bg.Add(vci_pt_data_cooked_in[i]);
            }

            InitializeComponent();
            SetPageValues();
        }

        private void SetPageValues()
        {

            int index = 0;
            RowDefinition rd = new RowDefinition();

            persons = new List<ExpandoObject>();
            ObservableCollection<Customer> bdd = new ObservableCollection<Customer>();

            int iCount = vci_pt_data_cooked_bg.Count();
            while (index < iCount)
            {
                int iColumnCount = 0;
                DataGridRow dgr = new DataGridRow();

                if (vci_pt_data_cooked_bg[index] != null)
                {
                    int iColumns = vci_pt_data_cooked_bg[index].Count();


                    while (iColumnCount < iColumns)
                    {
                        if (vci_pt_data_cooked_bg[index][iColumnCount] != null)
                        {
                            Customer bob = new Customer();
                            bob.FieldName = vci_pt_data_cooked_bg[index][iColumnCount].Pt_Column;
                            bob.FieldValue = vci_pt_data_cooked_bg[index][iColumnCount].Pt_Value;

                            bdd.Add(bob);
                            {
                                int i = 0;
                                bool bFound = false;

                                for (i = 0; (i < BackgroundDataGrid.Columns.Count) && !bFound; i++)
                                {
                                    if (BackgroundDataGrid.Columns[i].Header.Equals(bob.FieldName))
                                        bFound = true;
                                }
                                if (!bFound)
                                {
                                    DataGridTextColumn mycol = new DataGridTextColumn
                                    {
                                        Header = bob.FieldName,
                                        Binding = new Binding( bob.FieldName )
                                    };
                                    BackgroundDataGrid.Columns.Add( mycol );
                                }
                            }
                        }
                        iColumnCount++;
                    }
                }
                index++;
            }

            iCount = vci_pt_data_cooked_bg.Count();
            ObservableCollection<DataGridColumn> dgc = BackgroundDataGrid.Columns;
 
            index = 0;

            while (index < iCount)
            {
                int iCols = 0;
                var aperson = new ExpandoObject() as IDictionary<string, Object>;

                while (iCols < dgc.Count())
                {
                    bool bFound = false;
                    int y = 0;
                    string skey = dgc[iCols].Header.ToString();

                    if ( vci_pt_data_cooked_bg[index] != null )
                    {
                        while ( (y < vci_pt_data_cooked_bg[index].Length) && !bFound )
                        {
                            if (vci_pt_data_cooked_bg[index][y].Pt_Column.Equals(skey ) )
                            {
                                bFound = true;
                                aperson.Add( skey, vci_pt_data_cooked_bg[index][y].Pt_Value );
                            }
                            y++;
                        }
                        if (!bFound)
                        {
                            aperson.Add(skey, "_");
                        }
                    }
                    iCols++;
                }
                index++;
                persons.Add((ExpandoObject)aperson);
            }

            BackgroundDataGrid.ItemsSource = persons;
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
        public class Customer
        {
            public string FieldName { get; set; }
            public string FieldValue { get; set; }
        }
 
    }

 
}
//http://msdn.microsoft.com/en-us/library/system.dynamic.dynamicobject%28VS.100%29.aspx



===


I think the binding is wrong.

But this is the best I could decipher from online examples.

Please advise.

Boyd
Boyd D. Mills
mailto:BMills@VCIControls.ca

QuestionWpf doesnt recognize my xmlns for User Control Pin
tomr126-Jun-13 11:31
tomr126-Jun-13 11:31 
AnswerRe: Wpf doesnt recognize my xmlns for User Control Pin
tomr126-Jun-13 17:48
tomr126-Jun-13 17:48 
AnswerRe: Wpf doesnt recognize my xmlns for User Control Pin
Abhinav S26-Jun-13 18:31
Abhinav S26-Jun-13 18:31 
GeneralRe: Wpf doesnt recognize my xmlns for User Control Pin
tomr127-Jun-13 8:20
tomr127-Jun-13 8:20 
GeneralRe: Wpf doesnt recognize my xmlns for User Control Pin
Meshack Musundi3-Jul-13 1:02
professionalMeshack Musundi3-Jul-13 1:02 
Questionwindowmediasdk for silverlight Pin
brodcasting26-Jun-13 0:24
brodcasting26-Jun-13 0:24 
QuestionDraging Grids in WPF Pin
tomr125-Jun-13 16:06
tomr125-Jun-13 16:06 
AnswerRe: Draging Grids in WPF Pin
sorawit amorn27-Jun-13 11:25
sorawit amorn27-Jun-13 11:25 
GeneralRe: Draging Grids in WPF Pin
tomr11-Jul-13 15:44
tomr11-Jul-13 15:44 
GeneralRe: Draging Grids in WPF Pin
sorawit amorn3-Jul-13 5:32
sorawit amorn3-Jul-13 5:32 
AnswerRe: Draging Grids in WPF Pin
sorawit amorn3-Jul-13 5:33
sorawit amorn3-Jul-13 5:33 
Question[SOLVED] WPF Combobox background color Pin
Saksida Bojan22-Jun-13 7:31
Saksida Bojan22-Jun-13 7:31 
AnswerRe: WPF Combobox background color Pin
Mycroft Holmes22-Jun-13 13:43
professionalMycroft Holmes22-Jun-13 13:43 
GeneralRe: WPF Combobox background color Pin
Saksida Bojan22-Jun-13 20:43
Saksida Bojan22-Jun-13 20:43 
GeneralRe: WPF Combobox background color Pin
Mycroft Holmes22-Jun-13 21:48
professionalMycroft Holmes22-Jun-13 21:48 
GeneralRe: WPF Combobox background color Pin
Saksida Bojan22-Jun-13 23:09
Saksida Bojan22-Jun-13 23:09 
AnswerRe: WPF Combobox background color Pin
Abhinav S22-Jun-13 18:36
Abhinav S22-Jun-13 18:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.