2012-08-08 60 views
1

具有低於數據綁定類到Silverlight控件工具提示

Public Class Author 
{ 
    Public String Name{get;set;} 
    Public String Description{get;set;} 
    Public int NumberOfBooks{get;set;} 
} 

一個Author類和數據綁定List<Author>通過DataTemplate中以列表框像下面

<ListBox ItemsSource="{Binding Authors}" BorderThickness="0"> 
          <ListBox.ItemTemplate> 
           <DataTemplate> 
            <StackPanel ToolTipService.ToolTip="{Binding Description}" ToolTipService.Placement="Right"> 
             <TextBlock Text="{Binding Name}"></TextBlock> 
            </StackPanel> 
           </DataTemplate> 
          </ListBox.ItemTemplate> 
         </ListBox> 

如何生成使用XAML中提示描述聲明綁定像下面一樣

AuthorName (NumberOfBooks) 
Description 

回答

1

你可以簡單。

<TextBlock Text="{Binding Name}"> 
    <ToolTipService.ToolTip> 
    <ToolTip> 
     <StackPanel> 
     <TextBlock> 
      <Run Text="{Binding AuthorName}"/> 
      <Run Text=" "/> 
      <Run Text="{Binding NumberOfBooks}"/> 
     </TextBlock> 
     <TextBlock MaxWidth="150" 
       Text="{Binding Description}" TextWrapping="Wrap"/> 
     </StackPanel> 
    </ToolTip> 
    </ToolTipService.ToolTip> 
</TextBlock> 

還是看中了。

<TextBlock Text="{Binding Name}"> 
    <ToolTipService.ToolTip> 
     <ToolTip> 
     <StackPanel> 
      <Border Background="CadetBlue" Margin="5" Padding="5"> 
       <TextBlock Text="{Binding AuthorName}" HorizontalAlignment="Center"/> 
      </Border> 
      <TextBlock Text="{Binding NumberOfBooks, StringFormat='No. of Books: \{0\}'}"/> 
      <TextBlock MaxWidth="150" 
       Text="{Binding Description}" TextWrapping="Wrap"/> 
     </StackPanel> 
     </ToolTip> 
    </ToolTipService.ToolTip> 
</TextBlock> 

希望這有助於:)