Lionel Pire
Lionel Pire

Reputation: 368

Dynamic GroupName for radiobuttons in WPF (MVVM)

Right now, I have a DataGrid containing, along with other columns, 5 columns that contains a <RadioButton>

Each line has a GroupName that is the "id" in the table of the line, so I know it's unique.

But I'd like to add some lines to that DataGrid, but obviously, there isn't a generated groupname that I could use so I can select all of my radiobuttons in the new row at the same time

Is there a way to do it? Keep in mind that this is a MVVM approach

Here is a visual representation of the issue (The radiobuttons have a style that makes them invisible if unselected and an "X" if selected) Visual representation of the issue

Upvotes: 0

Views: 661

Answers (1)

Lionel Pire
Lionel Pire

Reputation: 368

I decided to use a GUID that is generated in the constructor of my object and use this property to name the GroupName property

public string GUID { get; set; }

public myObject()
{
    GUID = Guid.NewGuid().ToString();
}


<RadioButton GroupName="{Binding GUID}" />

Upvotes: 1

Related Questions