2010-11-30 11 views
1

J'essaye de changer la 3ème/dernière colonne.Comment personnaliser une colonne TreeView avec des contrôles HyperLink/LinkLabel pour chaque TreeViewItem dans cette colonne dans WPF?

Exemple de code:

<Window x:Class="WpfTest2.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:r="http://schemas.aspitalia.com/Ricciolo/Controls" 
     Title="MainWindow" Height="350" Width="525"> 
    <Grid> 
     <Grid.Resources> 


      <XmlDataProvider x:Key="data" Source="Data.xml"> 
      </XmlDataProvider> 

      <HierarchicalDataTemplate x:Key="dt" ItemsSource="{Binding XPath=outline}"> 
      </HierarchicalDataTemplate> 

     </Grid.Resources> 

     <Grid.RowDefinitions> 
      <RowDefinition Height="*" /> 
     </Grid.RowDefinitions> 

     <r:TreeView Name="Report" ItemsSource="{Binding Source={StaticResource data},XPath=/opml/body/outline/outline}" ItemTemplate="{StaticResource dt}"> 
      <r:TreeView.Columns> 
       <GridViewColumn Header="Title" DisplayMemberBinding="{Binding [email protected]}" Width="150" /> 
       <GridViewColumn Header="Childs" DisplayMemberBinding="{Binding [email protected]}" Width="100" /> 
       <GridViewColumn Header="Url" DisplayMemberBinding="{Binding [email protected]}" Width="200" /> 
      </r:TreeView.Columns> 
     </r:TreeView> 


    </Grid> 
</Window> 

Répondre

1

Essayez ceci:

 <r:TreeListView ItemsSource="{Binding Source={StaticResource data},XPath=/opml/body/outline/outline}" ItemTemplate="{StaticResource dt}"> 
     <r:TreeListView.Columns> 
      <GridViewColumn Header="Title" DisplayMemberBinding="{Binding [email protected]}" Width="150" /> 
      <GridViewColumn Header="Childs" DisplayMemberBinding="{Binding [email protected]}" Width="100" /> 
      <GridViewColumn Header="Url" Width="200"> 
       <GridViewColumn.CellTemplate> 
        <DataTemplate> 
         <TextBlock> 
          <Hyperlink NavigateUri="{Binding [email protected]}" RequestNavigate="Hyperlink_RequestNavigate"> 
           <TextBlock Text="{Binding [email protected]}" /> 
          </Hyperlink>  
         </TextBlock> 
        </DataTemplate> 
       </GridViewColumn.CellTemplate> 
      </GridViewColumn> 
     </r:TreeListView.Columns> 
    </r:TreeListView> 

Et dans le code derrière:

private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e) 
    { 
     Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri)); 
     e.Handled = true; 
    } 

J'ai trouvé la solution ici: http://nishantrana.wordpress.com/2009/03/26/using-hyperlink-in-wpf-application/