Silverlight DataGrid 資料繫結滑鼠移入到內容項時顯示類似ToolTip提示文字

暖楓無敵發表於2013-02-17

效果圖如下:

 

主要是呼叫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>

 

相關文章