Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I'd like to create a table to show which user has which software opened in their system.

To show if the user has the software or not, I'd like to create an ellipsis that would be colored green if true and red if false.

I should have no problem with the code, what i'm now trying to figure out (since i've never used WPF before) is the best approach.

I think I should create a data grid to have optimal control over the look of the grid itself, as i want the lines of the grid to appear. However, datagrids don't allow me to insert ellipsis in their cells.

I then tried using the Grid, which works great, but I found no possible way to customize the appearance of the grid lines. I can only find the option to show or not show grid lines, and I would like to specify color, width, style, etc.

So what should I do? Any suggestions?

Thanks
Posted
Comments
Sergey Alexandrovich Kryukov 22-Feb-13 15:33pm    
So, ellipsis or ellipse? These two things are totally unrelated. In principle, in WPF you can use them both, in any content, even in a grid view :-)
—SA

Hi.you can do following.your DataGridColumn must be like:
XML
<DataGridTemplateColumn Header="Status">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Button>
                                <Button.Template>
                                    <ControlTemplate TargetType="{x:Type Button}">
                                        <Ellipse Fill="{TemplateBinding Background}" Width="10" Height="10"/>
                                    </ControlTemplate>
                                </Button.Template>
                                <Button.Style>
                                    <Style TargetType="{x:Type Button}">
                                        <EventSetter Event="Button.Loaded" Handler="StatusButtonHandler"/>
                                    </Style>
                                </Button.Style>
                            </Button>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>


and in your codeBehind you can define a property for checking the status of users' software.
in here i define a IsLoad property:

C#
private void StatusButtonHandler(object sender, RoutedEventArgs e)
        {
            Button source = e.OriginalSource as Button;
            if (this.IsLoad == true)
            {
                source.Background = Brushes.Green;
            }
            else
            {
                source.Background = Brushes.Red;
            }
        }


my IsLoad property:
C#
public bool IsLoad
       {
           get;
           set;
       }


I hope this help you.
Good Luck
 
Share this answer
 
v2
Hi. i credate a DataGridCheckBoxColumn.this is more professional:
XML
<DataGridCheckBoxColumn Binding="{Binding IsFlagged}">
                                <DataGridCheckBoxColumn.HeaderTemplate>
                                    <DataTemplate >
                                        <Image Source="/Images/BlueFlag.png" Width="24" Height="24"/>
                                    </DataTemplate>
                                </DataGridCheckBoxColumn.HeaderTemplate>
                                <DataGridCheckBoxColumn.ElementStyle>
                                    <Style TargetType="{x:Type CheckBox}">
                                        <Setter Property="Height" Value="10"/>
                                        <Setter Property="Width" Value="10"/>
                                        <Setter Property="Template">
                                            <Setter.Value>
                                                <ControlTemplate TargetType="{x:Type CheckBox}">
                                                    <Ellipse x:Name="FlagEllipse" Fill="LightGray" Width="10" Height="10"/>
                                                    <ControlTemplate.Triggers>
                                                        <Trigger Property="IsChecked" Value="True">
                                                            <Setter TargetName="FlagEllipse" Property="Fill" Value="Red"/>
                                                        </Trigger>
                                                    </ControlTemplate.Triggers>
                                                </ControlTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </Style>
                                </DataGridCheckBoxColumn.ElementStyle>
                            </DataGridCheckBoxColumn>


"IsFlagged " is your property for checking.
 
Share this answer
 

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