Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I tried to create a method that set the color of a DataGridCell calculating it.
I created a resource that use this method:
XML
<UserControl.Resources>
    <ObjectDataProvider ObjectType="{x:Type l:D}"
              MethodName="CalculateBackColor" x:Key="CalculateBackColor">
        <ObjectDataProvider.MethodParameters>
            <system:Object/>
        </ObjectDataProvider.MethodParameters>
    </ObjectDataProvider>
</UserControl.Resources>

NB: I used an Object parameter because I tried to pass the cell itself or the DataGridCellInfo, but I don't know how. I used Object only for attempts. In a future, it will be
<ObjectDataProvider.MethodParameters>
    <DataGridCell/>
</ObjectDataProvider.MethodParameters>

I tried to bind this method to the background of the cell.
XML
<DataGrid IsReadOnly="True" ItemsSource="{Binding}">
    <DataGrid.CellStyle>
        <Style TargetType="DataGridCell">
            <Setter Property="Me" Value="{Binding
                    Source={StaticResource ResourceKey=FromDRToColor},
                    Path=MethodParameters[0], BindsDirectlyToSource=True}" />
            <Setter Property="Background" Value="{Binding
                    Source={StaticResource ResourceKey=FromDRToColor}}"/>
        </Style>
    </DataGrid.CellStyle>
</DataGrid>


Naturally, Setter Property = "Me" doesn't run.
Even inserting Setter Property = "Content" instead of "Me", the function receives as a parameter a null (perhaps because even the content has not been set, or maybe because I was wrong syntax)
How do I have to do?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900