Hy guys,
Please tell me,how can I use a column in xamGrid, such that if i don't bind the column (Key=null), it will not fail with error that the key can not be null ? As far as I see, this error is encountered even if I have UnboundColumns... Please provide me an example, if it possible to avoid this situation.
Thanks,
Alin
Through a direct key binding, no, you cannot bind to a field twice.
However you can bind to the field once via a normal column and then use an unbound column and set a value converter on the unbound column to display the value.
Something along these lines:
<ig:XamGrid x:Name="grid">
<ig:XamGrid.Columns>
<ig:TextColumn Key="MyField"></ig:TextColumn>
<ig:UnboundColumn Key="Extra" ></ig:UnboundColumn>
</ig:XamGrid.Columns>
</ig:XamGrid>
public partial class MainPage : UserControl
{
public MainPage()
InitializeComponent();
List<MyClass> l = new List<MyClass>();
l.Add(new MyClass() { MyField = "Hello" });
grid.ItemsSource = l;
((UnboundColumn)grid.Columns["Extra"]).ValueConverter = new MyConverter();
}
public class MyClass
public string MyField { get; set; }
public class MyConverter : IValueConverter
#region IValueConverter Members
object IValueConverter.Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
return ((MyClass)value).MyField;
object IValueConverter.ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
return value;
#endregion
Hi,
I have another question related to the columns. Is it possible to provide a way such that by using the Silverlight XamGrid to bind two columns to the same property?
Thank you both for your quick answers.
For most column types in the Grid, the Key property serves two purposes:
UnboundColumn is an exception to this however, still requiring a Key but only using it to uniquly identify the column within the grid, not to connect it to an ItemSource property.
So althought its still required on UnboundColumns, it actually does not connect it to any data in the items source.
Hope that helps.
Devin
Hi Alin,
All columns require a key.
However, for an UnboundColumn, the key can be anything, it just has to be unique.
-SteveZ