简体   繁体   中英

how to add a label in datagrid area in wpf c#?

I have a datagrid which populates list of files for conversion. I can add files

  1. By selecting files from folder through button click
  2. By drag and drop files to the datagrid area

I have done with these functionalities,but now we have a requirement to show the second option, "drag and drop files here" in the empty datagrid area initially. Once files are added this text should disappear.

My question is how to add a label or textblock in datagrid area?

it is possible to use a VisualBrush to draw a text on DataGrid background. Since text should be displayed only for empty grid, I set Background in Trigger for HasItems property

<DataGrid>
    <DataGrid.Style>
        <Style TargetType="DataGrid">
            <Style.Triggers>
                <Trigger Property="HasItems" Value="False">
                    <Setter Property="Background">
                    <Setter.Value>
                        <VisualBrush Stretch="None">
                            <VisualBrush.Visual>
                                <TextBlock Text="Drag'n'Drop"/>
                            </VisualBrush.Visual>
                        </VisualBrush>
                    </Setter.Value>
                    </Setter>
                </Trigger>
            </Style.Triggers>
        </Style>
    </DataGrid.Style>
</DataGrid>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM