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