tags:

views:

31

answers:

1

This is a very basic question. I have a grid, whose data context is bound to a entity framework service. I simply bound the context to service and I can see the data that is getting bound properly. Now, I want to change couple of coulmns to special controls. Like one column has true or false value and that column I want to display a radio button. One column is date value, I want to display date control. How would one go about doing it? Thanks.

A: 

I'm not exactly sure how to do the Radio Button portion of this, but something like this may get you started:

<ListBox x:Name="LayoutRoot" ItemsSource="{Binding Collection}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Text}"/>
                <CheckBox Content="True" IsChecked="{Binding Checked, Mode=TwoWay}"/>
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

In this case, you would have a checkbox being bound to the boolean value. I'm not exactly sure what you are using for a date control, but you should be able to place that in the stackpanel also and bind it to the dateproperty of your item.

In the above example, 'Collection' is an observable collection of 'MyObject' which is shown below:

MyObject.cs

public class MyObject
{
    public string Text { get; set; }
    public bool Checked { get; set; }
    public bool InverseChecked { get; set; }
    public DateTime Date { get; set; }
}

I also understand that you were using a grid, and I'm showing a ListBox. Not sure if this would work for you, but this is how we've approached it in the past.

Hope this helps!

JSprang