Results 1 to 3 of 3

Thread: VB.net 2010 - WPF Datagrid Cell Background Style Issue

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2007
    Posts
    64

    Question VB.net 2010 - WPF Datagrid Cell Background Style Issue

    So, I am trying to setup a datatrigger for a datagridcell in WPF that shows a red square when the cell contains the word "red". It works but the problem is I am modifying the background and when the row is selected it shows a white box around the square. I want to get rid of the white box and I have been looking for another way of going about what I want but can't figure it out. Below is the code and an example image.

    Code:
        <Style x:Key="dgJobsPriority" TargetType="DataGridCell">
            <Style.Triggers>
                <DataTrigger Binding="{Binding Priority}" Value="Red">
                    <Setter Property="Background">
                        <Setter.Value>
                            <DrawingBrush Stretch="None">
                                <DrawingBrush.Drawing>
                                    <DrawingGroup>
                                        <GeometryDrawing Brush="Red">
                                            <GeometryDrawing.Geometry>
                                                <RectangleGeometry Rect="0,0,16,16" />
                                            </GeometryDrawing.Geometry>
                                        </GeometryDrawing>
                                    </DrawingGroup>
                                </DrawingBrush.Drawing>
                            </DrawingBrush>
                        </Setter.Value>
                        </Setter> 
                </DataTrigger>
            </Style.Triggers>
            <Setter Property="Foreground" Value="#00000000"/>
        </Style>
    Name:  example.jpg
Views: 1497
Size:  16.4 KB

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Oct 2007
    Posts
    64

    Re: VB.net 2010 - WPF Datagrid Cell Background Style Issue

    Of course I figure it out not long after I post this ... so annoying when that happens. If anyone could provide some insight if this is an "acceptable" way of doing this or if there is a "better" way I would appreciate the input. WPF seems so powerful but also so confusing for just being markup at times.

    Code:
        <Style x:Key="dgJobsPriority" TargetType="DataGridCell">
            <Style.Triggers>
                <DataTrigger Binding="{Binding Priority}" Value="Red">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type DataGridCell}">
                                <Grid Background="{TemplateBinding Background}">
                                    <Canvas>
                                        <Rectangle Width="16" Height="16" Fill="Red" Canvas.Left="3" Canvas.Top="3" />
                                    </Canvas>
                                </Grid>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </DataTrigger>
            </Style.Triggers>
        </Style>

  3. #3
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: VB.net 2010 - WPF Datagrid Cell Background Style Issue

    Is it not a margin or a padding?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width