views:

138

answers:

1

I have a datagrid with one column having a radio button. I want to set the GroupName when a certain condition is reached. Below is the code

        <Custom:DataGrid.Columns>

                      <!-- ONLY ENABLED WHEN THE ITEM TYPE IS SINGLESELECT OR SINGLESELECT WITH ADDIOTIONAL DATA-->
            <Custom:DataGridTemplateColumn CanUserResize="False" MinWidth="20" >
                <Custom:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <RadioButton IsChecked="{Binding IsChecked}" d:DesignWidth="16" d:DesignHeight="16" GroupName="SingleChoiceSelection" Template="{DynamicResource RadioButtonTemplate}" Background="{DynamicResource BackgroundNew}" BorderBrush="#FF7A7171" Foreground="#FF6C6C6C" Margin="0" />
                    </DataTemplate>
                </Custom:DataGridTemplateColumn.CellTemplate>
            </Custom:DataGridTemplateColumn>


            <Custom:DataGridTextColumn Header="Choices"  Binding="{Binding ChoiceText}"  CellStyle="{DynamicResource DataGridCellStyle2}" MinWidth="150" />


        </Custom:DataGrid.Columns>

    </Custom:DataGrid>

The ItemSource contains a property called isChecked and I want to change the foreground color when isChecked is changed to true. How do i do this with a datatrigger?

A: 
<DataTrigger Binding="{Binding IsChecked}" Value="True" > 
    <Setter Property="Foreground" Value="Yellow" /> 
<DataTrigger> 
Veer
where do I place this code?
Farax
@Farax: Inside your `<DataTemplate><DataTemplate.Triggers>here</DataTemplate></DataTemplate.Triggers>`
Veer
ok m gonna try this
Farax
Got this error "Cannot find the Template Property 'Foreground' on the type 'System.Windows.Controls.ContentPresenter'"
Farax
Also tried changing Foreground to RadioButton.ForeGround to no avail
Farax
include `TargetName="NameOfYourElement"` in your setter. That is the name of the Element whose foreground you wish to change. You can give name to your element using the `Name` Attribute.
Veer
it worked but not as i expected :S Once I check the radiobutton, nothing changes immediatly and I have to select another row and have to come back to the original ones to find the changed foreground color.
Farax
I think the default blue Highlight during selection hides the foreground color. If that is so, try changing the foreground color of the border.
Veer