Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
160
Databinding
posted

Hello,

 

I have a question regarding your XamGrid for Silverlight 4.0.

Currently, I'm using the Standard DataGrid from Silverlight Tools and would like to use your XamGrid. However, I don't know how to use specific Binding objects for additional DataColumns that are created and added to the DataGrid after an ItemSource has been set.

 

The code for the Standard Silverlight DataGrid looks like this:

 

XAML

 

<sdk:DataGrid AutoGenerateColumns="True" Height="100" VerticalAlignment="Top" HorizontalAlignment="Stretch" Margin="0,0,0,0" Name="DetailsGrid" />

 

C#

 

...

DetailsGrid.ItemsSource = someGraphicsInAList;

Graphic oneGraphic = SelectedGraphics.First<Graphic>();

foreach (KeyValuePair<string, object> kvp in oneGraphic.Attributes)

{

       DataGridTextColumn column = new DataGridTextColumn();

column.Header = kvp.Key;

       column.Binding = new System.Windows.Data.Binding();

       column.Binding.Mode = BindingMode.OneWay;

GraphicAttributesConverter oGraphicAttributesConverter = new GraphicAttributesConverter();

       column.Binding.Converter = oGraphicAttributesConverter;

       column.Binding.ConverterParameter = kvp.Key;

       DetailsGrid.Columns.Add(column);

}

...

public class GraphicAttributesConverter : IValueConverter

    {

 

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

        {

            return ((Graphic)value).Attributes[parameter.ToString()];

        }

 

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

        {

            throw new NotImplementedException();

        }

    }

 

How Do I do this with the XamGrid?

Thanks,
Dennis

Parents
No Data
Reply
  • 6912
    Suggested Answer
    posted

    Hi,

    As far as I can see from your code, you are just adding a text column with a converter. To get the same result with XamGrid you can use the following code snippet:

    using Infragistics.Controls.Grids;
    ...
    TextColumn textColumn = new TextColumn { Key = columnKey };
    textColumn.ValueConverter = new YourValueConverter();
    textColumn.ValueConverterParameter = parameter;
    this.xamGrid.Columns.Add(textColumn);
    ...

    If you want to add a TemplateColumn at run-time you can look at this thread for more information.

    Hope this helps

Children