SumGuy
SumGuy

Reputation: 491

WPF Binding a class

Probably a simple question but one that eludes me nonetheless.

I have a class:

public class Person
{
    public string Name{ get; set; }
    public int Age{ get; set; }
}

An arry of which, is bound to a listview:

    <ListView Name="lvDrawings">
        <ListView.View>
            <GridView>
                <GridViewColumn>
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <RadioButton Checked="rbSelected_Checked" GroupName="rbgSelected" Tag="{Binding Path=Person}" />
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
                <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path=Name}" />
                <GridViewColumn Header="Age" DisplayMemberBinding="{Binding Path=Age}" />
            </GridView>
        </ListView.View>
    </ListView>

As you can see on the Radio Button I've attempted to bind the class to the tag so that I can utilise the selected row's class. As you can guess, this doesn't work.

How would I be able to do this or is there a much better way.

Thanks in advance, SumGuy

Upvotes: 1

Views: 130

Answers (1)

HCL
HCL

Reputation: 36765

The following will do what you're looking for:

<RadioButton Checked="rbSelected_Checked" GroupName="rbgSelected" Tag="{Binding}" />                        

Upvotes: 1

Related Questions