خرید بک لینک

Vote count: 0

I want to have the MessageListView to scroll to the bottom whenever it appears or gets its data updated. How can I do this?

The xaml page:

<Page
x:Class="MyApp.Pages.ChatsPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MyApp.Pages"
xmlns:data="using:MyApp.Model.Profile"
xmlns:vm="using:MyApp.ViewModel"
xmlns:util="using:MyApp.Util"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Page.Transitions>
    <TransitionCollection>
        <NavigationThemeTransition />
    </TransitionCollection>
</Page.Transitions>


<Page.Resources>

   <util:BoolToVisibilityConverter x:Key="BoolToVisConverter" />

    <!--CollectionViewSource x:Name="Chats"
        Source="{x:Bind ViewModel}"/>
    <CollectionViewSource x:Name="Chat"
        Source="{Binding ChatViewModel, Source={StaticResource Chats}}"/>
    <CollectionViewSource x:Name="Messages"
        Source="{Binding MessageViewModel, Source={StaticResource Chat}}"/-->

    <DataTemplate x:Key="MasterListViewItemTemplate" >
        <Grid Margin="0,11,0,13" BorderBrush="Gray" BorderThickness="2">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <TextBlock Text="{Binding ChatName}" Style="{ThemeResource ChatListTitleStyle}" />

            <TextBlock
                Text="{Binding LastMessage}"
                Grid.Row="1"
                MaxLines="1"
                Style="{ThemeResource ChatListTextStyle}" />
            <TextBlock
                Text="{Binding LastSender}"
                Grid.Column="1"
                Margin="12,1,0,0"
                Style="{ThemeResource ChatListLastSenderStyle}" />
        </Grid>
    </DataTemplate>

    <DataTemplate x:Key="DetailContentTemplate">

        <ListView x:Name="MessageList" ItemsSource="{Binding Messages}" ScrollViewer.VerticalScrollMode="Auto">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <StackPanel BorderBrush="Black" BorderThickness="1" Padding="1">
                        <TextBlock Text="{Binding Message}" Style="{StaticResource NewsfeedTextStyle}"/>
                        <Image Visibility="{Binding Path=IsPhoto, Converter={StaticResource BoolToVisConverter} }" Source="{Binding Photo}" />
                        <Image Visibility="{Binding Path=IsReaction, Converter={StaticResource BoolToVisConverter} }" Width="200" Height="200" Source="{Binding Reaction}" />
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding Sender}" Style="{StaticResource NewsfeedTimestampStyle}" Margin="1"/>
                            <TextBlock Text="{Binding SentTime}" Style="{StaticResource NewsfeedTimestampStyle}" Margin="1"/>
                        </StackPanel>
                    </StackPanel>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </DataTemplate>

</Page.Resources>

<Grid x:Name="LayoutRoot" Loaded="LayoutRoot_Loaded">
    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="AdaptiveStates" CurrentStateChanged="AdaptiveStates_CurrentStateChanged">
            <VisualState x:Name="DefaultState">
                <VisualState.StateTriggers>
                    <AdaptiveTrigger MinWindowWidth="720" />
                </VisualState.StateTriggers>
            </VisualState>

            <VisualState x:Name="NarrowState">
                <VisualState.StateTriggers>
                    <AdaptiveTrigger MinWindowWidth="0" />
                </VisualState.StateTriggers>

                <VisualState.Setters>
                    <Setter Target="MasterColumn.Width" Value="*" />
                    <Setter Target="DetailColumn.Width" Value="0" />
                    <Setter Target="MasterListView.SelectionMode" Value="None" />
                </VisualState.Setters>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>

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

    <Grid.ColumnDefinitions>
        <ColumnDefinition x:Name="MasterColumn" Width="320" />
        <ColumnDefinition x:Name="DetailColumn" Width="*" />
    </Grid.ColumnDefinitions>

    <TextBlock
        Text="Chats"
        Margin="12,8,8,8"
        Style="{ThemeResource TitleTextBlockStyle}" />

    <ListView
        x:Name="MasterListView"
        Grid.Row="1"
        ItemContainerTransitions="{x:Null}"
        ItemTemplate="{StaticResource MasterListViewItemTemplate}"
        Background="{StaticResource ApplicationPageBackgroundThemeBrush}"
        IsItemClickEnabled="True"
        ItemClick="MasterListView_ItemClick">
        <ListView.ItemContainerStyle>
            <Style TargetType="ListViewItem">
                <Setter Property="HorizontalContentAlignment" Value="Stretch" />
            </Style>
        </ListView.ItemContainerStyle>
    </ListView>

    <ContentPresenter
        x:Name="DetailContentPresenter"
        Grid.Column="1"
        Grid.RowSpan="2"
        BorderThickness="1,0,0,0"
        Padding="24,0"
        BorderBrush="{ThemeResource SystemControlForegroundBaseLowBrush}"
        Content="{x:Bind MasterListView.SelectedItem, Mode=OneWay}"            
        ContentTemplate="{StaticResource DetailContentTemplate}">
        <ContentPresenter.ContentTransitions>
            <!-- Empty by default. See MasterListView_ItemClick -->
            <TransitionCollection />
        </ContentPresenter.ContentTransitions>
    </ContentPresenter>
</Grid>

asked 6 mins ago

برچسب: نویسنده: استخدام کار تاريخ: پنجشنبه 20 خرداد 1395 ساعت: 2:44

صفحه بندی