Update LongListSelector item DataTemplate dynamically
I have a longlistselector control which shows a list of items. My items
are custom, just like in this code:
<toolkit:LongListSelector x:Name="RecentiList" IsFlatList="True">
<toolkit:LongListSelector.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical" Hold="Hold_Item">
<StackPanel Orientation="Horizontal"
HorizontalAlignment="Stretch">
<StackPanel Width="10" Margin="0,10,10,0"
Background="{StaticResource
PhoneAccentBrush}">
</StackPanel>
<StackPanel Width="340"
Orientation="Vertical"
Margin="15,0,0,0">
<StackPanel Height="10" />
<TextBlock Text="{Binding
Preview}" Margin="0,0,0,0"
TextWrapping="Wrap" Width="340"
Height="Auto" FontSize="20"
FontWeight="Bold"/>
<StackPanel Orientation="Horizontal">
<TextBlock Text="da "
Margin="0,0,0,0" FontSize="20"
Foreground="{StaticResource
PhoneAccentBrush}"/>
<TextBlock Text="{Binding
Username}" Margin="0,0,0,0"
FontSize="20"
Foreground="{StaticResource
PhoneAccentBrush}"/>
<TextBlock Text=" - "
Margin="0,0,0,0" FontSize="20"
Foreground="{StaticResource
PhoneAccentBrush}"/>
<TextBlock Text="{Binding
DataCalc}" Margin="0,0,0,0"
FontSize="20"
Foreground="{StaticResource
PhoneAccentBrush}"/>
</StackPanel>
<StackPanel Height="10" />
</StackPanel>
<StackPanel
HorizontalAlignment="Stretch"
Margin="15,0,0,0"
Orientation="Horizontal" Width="80">
<Image Width="40" Height="40"
Source="/Assets/AppBar/appbar.reply.people.png"></Image>
<TextBlock Text="{Binding
Risposte}" FontSize="27"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontFamily="Portable User
Interface"/>
</StackPanel>
</StackPanel>
<Border x:Name="SecBord"
BorderBrush="{StaticResource
PhoneAccentBrush}" BorderThickness="2"
Height="1" Margin="0,0,0,0"
VerticalAlignment="Top" />
</StackPanel>
</DataTemplate>
</toolkit:LongListSelector.ItemTemplate>
</toolkit:LongListSelector>
The item layout is not so important, but have a look to the root
StackPanel element inside DataTemplate tag: I added a listener to the Hold
gesture. I'd like to have a StackPanel overlayed on the item I've just
pressed on, and have the possibilty to return to the hold item layout as
well. I really can't figure out how to switch between two layouts.
This is my first - and wrong - attempt of updating the item layout:
Private Sub Hold_Item(sender As Object, e As
System.Windows.Input.GestureEventArgs)
'root StackPanel element
Dim SP As StackPanel = DirectCast(sender, StackPanel)
SP = New StackPanel() With {.Height = 30, .Width = 100,
.Background = New SolidColorBrush(Colors.Green)}
End Sub
No comments:
Post a Comment