Silverlight DataGrid 数据绑定鼠标移入到内容项时显示类似ToolTip提示文本

效果图如下:

Silverlight DataGrid 数据绑定鼠标移入到内容项时显示类似ToolTip提示文本

 

主要是调用ToolTipService.ToolTip属性

主要代码如下:

                               <sdk:DataGrid Margin="4,36,8,7" DataContext="{Binding}" IsReadOnly="True" AutoGenerateColumns="False" x:Name="dg" SelectionChanged="dg_SelectionChanged" FontSize="14.667" FontFamily="Microsoft YaHei" LoadingRow="dg_LoadingRow" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Hidden" d:LayoutOverrides="HorizontalMargin">
                                        <sdk:DataGrid.Columns>

                                            <sdk:DataGridTemplateColumn Header="序号"  Width="50" HeaderStyle="{StaticResource aHeaderStyle}">
                                                <sdk:DataGridTemplateColumn.CellTemplate>
                                                    <DataTemplate>
                                                        <TextBlock TextAlignment="Center"  VerticalAlignment="Center">
                                                             <ToolTipService.ToolTip>
                                                                    <StackPanel Orientation="Horizontal">
                                                                        <TextBlock Text="{Binding Name}" Foreground="Red"  VerticalAlignment="Center"></TextBlock>
                                                                    </StackPanel>
                                                              </ToolTipService.ToolTip>
                                                        </TextBlock>
                                                    </DataTemplate>
                                                </sdk:DataGridTemplateColumn.CellTemplate>
                                            </sdk:DataGridTemplateColumn>

                                            <sdk:DataGridTemplateColumn Header="工程名称"  Width="200" HeaderStyle="{StaticResource aHeaderStyle}">
                                                <sdk:DataGridTemplateColumn.CellTemplate>
                                                    <DataTemplate>
                                                        <TextBlock FontSize="14.667" Text="{Binding Name}"   HorizontalAlignment="Left" VerticalAlignment="Center">
                                                              <ToolTipService.ToolTip>
                                                                    <StackPanel Orientation="Horizontal">
                                                                        <TextBlock Text="{Binding Name}" Foreground="Red"  VerticalAlignment="Center"></TextBlock>
                                                                    </StackPanel>
                                                              </ToolTipService.ToolTip>
                                                        </TextBlock>
                                                    </DataTemplate>
                                                </sdk:DataGridTemplateColumn.CellTemplate>
                                            </sdk:DataGridTemplateColumn>

                                        </sdk:DataGrid.Columns>
                                    </sdk:DataGrid>

 

上一篇:数据库常见问题的解决办法


下一篇:Silverlight实用窍门系列:18.DataGrid内绑定ComboBox和ListBox以及取值【附带源码实例】