Search code examples
c#wpfdata-bindingstack-overflowstaticresource

WPF Showing a boolean with radiobuttons


I'm currently in the process of making an application that has some CRUD views. I wanted to show a boolean in one of my views for editing a row. I used this answer here to try and solve this problem. I can edit the row once, if I try again I get a stackoverflow exception (whether I change to boolean value or not)

Resource declaration:

<UserControl.Resources>
    <bconv:BoolInverterConverter x:Key="BoolInverterConverter" />
</UserControl.Resources>

Radio buttons:

<RadioButton Grid.Column="0" GroupName="istemplate"
                                 Content="Yes" IsChecked="{Binding Survey.isTemplate, Mode=TwoWay}" />
                    <RadioButton Grid.Column="1" GroupName="istemplate"  Content="No" Margin="10,0,0,0"
                                 IsChecked="{Binding Survey.isTemplate, Mode=TwoWay, Converter={StaticResource BoolInverterConverter}}" />

The item I'm trying to edit the boolean (isTemplate) of:

[Table("Survey")]
public class Survey : EntityBase
{
    [Required, StringLength(50)]
    public string Name { get; set; }
    public User ConfirmedBy { get; set; }
    public Boolean isTemplate { get; set; }
    public Assignment Assignment { get; set; }
    public User User { get; set; }
    [DataType(DataType.Date)]
    public DateTime Date { get; set; }
}

If I forgot to include some information please ask!


Solution

  • The problem has been solved thanks to @sramalingam24 comment

    That should be a check box not a pair of radio buttons, where updating one calls the other leading to a cycle and the stack overflow

    The helper class I was using earlier can simply be deleted. All that's necessary is the CheckBox