locked
How to enable copying of text inside listview datetemplate

    Question

  • Hello,

    I am making demo chat application and users chats are displayed In listview and by default listview does now allow to select contents which are in its datatemplate, So my question is how to allow user to select and copy that chat something like Skype app.

    Thanks in advance.


    • Edited by zee_patel Friday, October 10, 2014 10:18 AM
    Friday, October 10, 2014 10:18 AM

Answers

  • You cannot set the IsHitTestVisible property of the ListView to false if you want to be able to interact with it by for example selecting the text in the read-only TextBoxes:

     
    <ListView
          x:Name="chatListView"
         AutomationProperties.AutomationId="chatListView"
         AutomationProperties.Name="Items"
        Grid.Row="2"
         Margin="120,0,0,0"
          IsItemClickEnabled="False" 
          Visibility="Visible"
          IsHitTestVisible="True"
        ItemTemplate="{StaticResource ChatTemplate}"
         SelectionMode="None"
         IsSwipeEnabled="True"     
                    >
     </ListView>

    Please remember to mark helpful posts as answer and/or helpful and please remember to start a new thread for any new question your may have.

    • Marked as answer by zee_patel Monday, October 13, 2014 11:44 AM
    Saturday, October 11, 2014 12:37 PM

All replies

  • How does your DataTemplate look like then? You could replace any TextBlock elements in the DataTemplate with readonly TextBox elements for the user to be able to select the text:

    <TextBox Background="Transparent" BorderThickness="0" Text="{Binding Text, Mode=OneWay}" IsReadOnly="True" TextWrapping="Wrap"/>
    

    Friday, October 10, 2014 10:50 AM
  • Hi Magnus,

    Thanks for reply.

    I already try that but its not working. Here is my demo xaml code for it. Used dummy data to bind listview itemsource from codebehind

    <DataTemplate x:Key="ChatTemplate">
                <Grid HorizontalAlignment="Stretch">
                    <Grid  HorizontalAlignment="Right"  >
                        <Border BorderBrush="Orange" BorderThickness="1"  CornerRadius="10" HorizontalAlignment="Left" Height="auto"  VerticalAlignment="Top">
                           
                            <Grid VerticalAlignment="Stretch">
                              
                                <TextBox Grid.Row="1" Margin="5"  MinHeight="30" IsReadOnly="True" Text="{Binding message}" TextWrapping="Wrap"  Foreground="Black" FontSize="14"  />
                            </Grid>
                        </Border>
                    </Grid>
                </Grid>
    </DataTemplate>
     <ListView
          x:Name="chatListView"
         AutomationProperties.AutomationId="chatListView"
         AutomationProperties.Name="Items"
        Grid.Row="2"
         Margin="120,0,0,0"
          IsItemClickEnabled="False" 
          Visibility="Visible"
          IsHitTestVisible="False"
        ItemTemplate="{StaticResource ChatTemplate}"
         SelectionMode="None"
         IsSwipeEnabled="True"     
                    >
     </ListView>


    Friday, October 10, 2014 1:04 PM
  • You cannot set the IsHitTestVisible property of the ListView to false if you want to be able to interact with it by for example selecting the text in the read-only TextBoxes:

     
    <ListView
          x:Name="chatListView"
         AutomationProperties.AutomationId="chatListView"
         AutomationProperties.Name="Items"
        Grid.Row="2"
         Margin="120,0,0,0"
          IsItemClickEnabled="False" 
          Visibility="Visible"
          IsHitTestVisible="True"
        ItemTemplate="{StaticResource ChatTemplate}"
         SelectionMode="None"
         IsSwipeEnabled="True"     
                    >
     </ListView>

    Please remember to mark helpful posts as answer and/or helpful and please remember to start a new thread for any new question your may have.

    • Marked as answer by zee_patel Monday, October 13, 2014 11:44 AM
    Saturday, October 11, 2014 12:37 PM
  • Hi Magnus,

    Thanks for your answer. It was really silly thing I missed.

    I also want to make url inside my message to be displayed as hyperlink, say my message contains "Hey www.bing.com is awesome" than how to make that url as clickable hyperlink.

    Monday, October 13, 2014 5:37 AM
  • Hi Magnus,

    Thanks for your answer. It was really silly thing I missed.

    I also want to make url inside my message to be displayed as hyperlink, say my message contains "Hey www.bing.com is awesome" than how to make that url as clickable hyperlink.


    Please don't ask several questions in the same thread. Remember to mark any helpful posts as answer to close the thread and then open a new one if you have a new question.

    To display a clickable hyperlink in the DataTemplate you could use a HyperlinkButton:

    <StackPanel Orientation="Horizontal">
    <TextBlock Text="Hey "/>
    <HyperlinkButton NavigateUri="http://www.bing.com">www.bing.com</HyperlinkButton>
    <TextBlock Text=" is awesome!"/>

     

    How to link to external webpages (XAML): http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh868173.aspx

    • Marked as answer by zee_patel Monday, October 13, 2014 11:44 AM
    • Unmarked as answer by zee_patel Monday, October 13, 2014 11:44 AM
    Monday, October 13, 2014 10:36 AM
  • Hi Magnus,

    Thanks for reply.

    Please find my thread Here. Messages are not static so I can't go with your solution. It may contain hyperlink or may not or may be more than one hyperlink so what to do in that case.

    I previously posted that thread for textblock but it is not working for textboxes.



    • Edited by zee_patel Monday, October 13, 2014 11:53 AM
    Monday, October 13, 2014 11:47 AM