locked
Polygon with differents colors in DataGrid RRS feed

  • Question

  • Hi guys!!

    I’m using a DataGrid to show some register of my DB. I need have a column (created by code behind C#) that will show a Polygon.

    I have a "status" property in my table that can be: 0 (zero must show black), 1 (one must show green) and 2 (two must show red).

    I tried do this using a lot of differents codes but anyone help me, because I need change the color of Polygon depending of my register. I managed to put a Polygon as code below:

    DataGridTemplateColumn tratamentoNovoColumn = new DataGridTemplateColumn();
     
    private void wcf_completed(object sender, PersonCompletedEventArgs e)
    {
         //Change the color using "e.Result.Person.Status".
     
         //Change the cellTemplate to a resource
         tratamentoNovoColumn.CellTemplate = this.Resources["DateTemplate"] as DataTemplate;
    }
     
    ListViewDataGrid.Columns.Add(tratamentoNovoColumn);

    My xaml where I have my DataGrid, I passed a fix color to my Polygon

    <UserControl.Resources>
            <DataTemplate x:Key="DateTemplate">
                <Polygon Points="0,0 20,10, 0,20" Fill="Black"
                         VerticalAlignment="Center" HorizontalAlignment="Center"/>
            </DataTemplate>
    </UserControl.Resources>

    I hope that somebody can help me. Thank you a lot!!


    Atenciosamente, Seratti.

    Tuesday, April 22, 2014 4:55 PM

All replies

  • Hi,

    As far as I know, there are no built-in methods in .Net framework or in GDI+ that you can draw a polygon (triangle) with different colored sides directly, I believe we have to implement this function by ourselves.

    As you mentioned, you can just draw 3 lines with different colors, or just present a bitmap with a polygon, and you modify the bitmap first.

    Thanks.

    Friday, April 25, 2014 7:00 AM