Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to pass content property of Control as CommandParameter WPF

I have WPF project that has 19 radio button. I want to set Command property each of them.
To separate all command actions, I want to send RadioButton Content property as a CommandParameter.

I try to define setter for CommandParameter property and I set {Binding Path=Content}for Value as you can see below.

But it is not work.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

 <Style TargetType="RadioButton">
        <Setter Property="VerticalAlignment" Value="Center"/>
        <Setter Property="HorizontalAlignment" Value="Left"/>
        <Setter Property="Margin" Value="5"/>
        <Setter Property="Command" Value="{Binding SelectionChangedCommand}"/>
        <Setter Property="CommandParameter" Value="{Binding Path=Content}"/>
    </Style>
          

 <RadioButton Content="Area"/>
            <RadioButton Content="Unit"
                         Grid.Row="1"/>
            
            <RadioButton Content="Transom Count"
                         Grid.Row="2"
                         CommandParameter="Transom Count"/>
            <RadioButton Content="Mullion Count"
                         Grid.Row="3"/>
            <RadioButton Content="Transom And Mulliom Count"
                         Grid.Row="4"/>
            <RadioButton Content="Frame Count"
                         Grid.Row="5"/>
            <RadioButton Content="Frame + Transom + Mullion Count"
                         Grid.Row="6"/>
            <RadioButton Content="Corner Points"
                         Grid.Row="7"/>
            <RadioButton Content="T Connections"
                         Grid.Row="8"/>

            <RadioButton Content="Left"
                         Grid.Column="1"/>
            <RadioButton Content="Right"
                         Grid.Column="1"
                         Grid.Row="1"/>
            <RadioButton Content="Top"
                         Grid.Column="1"
                         Grid.Row="2"/>
            <RadioButton Content="Bottom"
                         Grid.Column="1"
                         Grid.Row="3"/>
            <RadioButton Content="Perimeter"
                         Grid.Column="1"
                         Grid.Row="4"/>
            <RadioButton Content="Transom Length"
                         Grid.Column="1"
                         Grid.Row="5"/>
            <RadioButton Content="Mullion Length"
                         Grid.Column="1"
                         Grid.Row="6"/>
            <RadioButton Content="Transom + Mullion Length"
                         Grid.Column="1"
                         Grid.Row="7"/>
            <RadioButton Content="Perimeter + Transom + Mullion Length"
                         Grid.Column="1"
                         Grid.Row="8"/>

enter image description here

>Solution :

 <Style TargetType="RadioButton">
        <Setter Property="VerticalAlignment" Value="Center"/>
        <Setter Property="HorizontalAlignment" Value="Left"/>
        <Setter Property="Margin" Value="5"/>
        <Setter Property="Command" Value="{Binding SelectionChangedCommand}"/>
        <Setter Property="CommandParameter" Value="{Binding Content, RelativeSource={RelativeSource Self}}"/>
    </Style>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading