I need to show a list of tweets. each tweet can be highlighted programmatically and also I can add some new controls to the tweet item. and I am using data binding.
for my purpose above, I thought of using a LongListSelector but it is too buggy, and it seems that I can't access a collection of its items (can I?). what else is suitable for showing a list of items, each item can contain some other controls, and also supports binding? I don't see another thing in the toolbox? is there any ester egg?
It's windows phone 8 app.
You can use a ListBox
<ListBox Name="listboxTimeline" Width="450" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,5,0,5" >
<Button Click="btn1_Click" >
<StackPanel VerticalAlignment="Top">
<Image Name="image" Source="{Binding ImageSource}" />
</StackPanel>
</Button>
<StackPanel Width="337">
<TextBlock Text="{Binding UserName}" />
<TextBlock Text="{Binding Content}" TextWrapping="Wrap" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
And then you can data bind to this from your CS page. ( The above code is just a sample)
Related
I am parsing a RSS Feed from one site and storing it in listbox1 and then parsing another RSS storing it in listbox2. Now I want to combine the data of listbox1 and listbox2 in listbox3. It might sound silly but I am unable to do it. The main problem is I am not able to access the controls inside the listbox.
<ListBox x:Name="list1" ItemsSource="{Binding RSSData}" DataContext="{Binding RSSData}" Visibility="Collapsed">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock HorizontalAlignment="Center" x:Name="txtpubDate" Foreground="#FF170505" Text="{Binding Path=pubDate}" TextDecorations="Underline" ></TextBlock>
<TextBlock Padding="18" Foreground="#FF0E0101" x:Name="txtTitle" TextWrapping="Wrap" Text="{Binding Path=Title}" FontWeight="Bold"></TextBlock>
<Image Height="200" x:Name="imageLink" Source="{Binding strImg}"></Image>
<TextBlock Foreground="#FF0F0202" Padding="35" TextTrimming="WordEllipsis" HorizontalAlignment="Left" x:Name="txtDesc" Margin="2" TextWrapping="Wrap" Text="{Binding Path=Description,Converter={StaticResource RssTextTrimmer}}"></TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
This is the XAML code of my listbox1 and I am trying to do it with listbox3.itemsource=listbox1.itemsource; but nothing is happening.
I also tried to add data in this way: listbox3.items.add(listbox.items[i])
but nothing is working.
Please help.
You can loop through the contents of the listbox and add them one by one for instance:
foreach(object item in listbox1.items)
{
listbox3.items.add(item);
}
and then do the same for listbox2.
I have 10 checkboxes in a listbox in windows phone.
My xaml file for checkbox into listbox is given below:
<ListBox x:Name="notificationSettingsListBox" Grid.Row="1" Margin="20,20,20,20" Background="#e79e38" >
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Background="#055cc3" Width="500" Height="200">
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding channel_name}" Foreground="White" FontSize="31" TextAlignment="Left" TextWrapping="Wrap" />
<CheckBox Content="Enable Notification" Checked="pushNotiOnCheckBox_Checked" Unchecked="pushNotiOnCheckBox_Unchecked"/>
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
How can I access all checkboxes one by one like checkbox1.checked=true or checkbox2.checked=false and so on?
I see that you subscribe to both Checked and Unchecked events, one thing you could do is add this in the handlers
var box = (sender as CheckBox);
var value = box.IsChecked;
I'm developing a windows 8 metro application with a data-bound gridview xaml control.
I've added a ring progress bar named progressRingGroup to header of the groups as seen below.
<ProgressRing x:Name="progressRingGroup" IsActive="True" Visibility="Visible" Width="16" Height="16" Margin="0,-7,0,0"/>
I want to programmatically access the ring-progress-bar from my code (so I can start/stop it) but as my grid-view is databound I don't know how to do so.
I've multiple groups in the gridview and need to access all of them separately.
Here's my gridview's groupstyle xaml definition;
<GridView.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<Grid Margin="1,0,0,6">
<Button
AutomationProperties.Name="Group Title"
Click="Header_Click"
Style="{StaticResource TextPrimaryButtonStyle}" >
<StackPanel Orientation="Horizontal">
<ProgressRing x:Name="progressRingGroup" IsActive="True" Visibility="Visible" Width="16" Height="16" Margin="0,-7,0,0"/>
<TextBlock Text="{Binding Title}" Margin="6,-7,10,10" Style="{StaticResource GroupHeaderTextStyle}" />
<TextBlock Text="{StaticResource ChevronGlyph}" FontFamily="Segoe UI Symbol" Margin="0,-7,0,10" Style="{StaticResource GroupHeaderTextStyle}"/>
</StackPanel>
</Button>
</Grid>
</DataTemplate>
</GroupStyle.HeaderTemplate>
<GroupStyle.Panel>
<ItemsPanelTemplate>
<VariableSizedWrapGrid ItemWidth="75" ItemHeight="150" Orientation="Vertical" Margin="0,0,80,0" MaximumRowsOrColumns="3"/>
</ItemsPanelTemplate>
</GroupStyle.Panel>
</GroupStyle>
</GridView.GroupStyle>
Help appreciated.
If you want to be able to control the IsActive property of each progress ring, add a bool property to your group data model, and bind IsActive to that property. That way you can control each ProgressRing without having to programatically access all of them.
For example:
<ProgressRing x:Name="progressRingGroup" IsActive="{Binding GroupLoading}" Visibility="Visible" Width="16" Height="16" Margin="0,-7,0,0"/>
If you still want to access each programmatically, you could assign a Loaded event to the ProgressRing in the DataTemplate, and when the event fires, grab a reference to the ring (sender).
I can't find an exact word to describe my problem (so sorry for that).
What I want to do is :
Create a Stackpanel which will hold vertically other StackPanels, those StackPanels will be created dynamically depending on the number of rows in the Database, each StackPanel will hold two Labels (Title & Description) and must Databind their values from the Linq request.
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<Label x:Name="Title" />
<Label x:Name="Description" />
</StackPanel>
</Stackpanel>
I have already created my Linq request using the ObservableCollection & IEnumerable. Actually I can get the values and print them using Debug.WriteLine() command.
Can any one help me with some tips ?
Try using ItemsControl
<StackPanel>
<ItemsControl ItemsSource="{Binding YourObservableCollection}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Label Content="{Binding Value1}"></Label>
<Label Content="{Binding Value2}"></Label>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
I have something like this:
<ListBox Height="456" Margin="30,113,0,0" x:Name="listBox1" Width="446" Background="Black">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28" Orientation="Horizontal">
<TextBlock Text="{Binding name}" FontSize="28" Padding="10" >
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener
Hold="GestureListenerHold" />
</toolkit:GestureService.GestureListener>
</TextBlock>
<TextBlock Text="{Binding id}" FontSize="24" Padding="10" >
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener
Hold="GestureListenerHold" />
</toolkit:GestureService.GestureListener>
</TextBlock>
<TextBlock Text="{Binding status}" FontSize="24" Padding="10">
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener
Hold="GestureListenerHold" />
</toolkit:GestureService.GestureListener>
</TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
and in my app i do:
data = (List<Device>)serializer.Deserialize(stream);
this.listBox1.ItemsSource = data;
on every textblock I have a gesture listener which should provide the user with the option to change 'name', so when they hold the textblock the app navigates him to another page where he fills in the form.
My question is how to find the texblock which is binding 'name' when I click and hold another texblock?
You could use Linq-to-VisualTree, a utility which I wrote which allows you to navigate the visual tree:
http://www.scottlogic.co.uk/blog/colin/2010/03/linq-to-visual-tree/
Firstly, name the TextBlock so that it can be uniquely identified:
<TextBlock x:Name="NameText" Text="{Binding name}" FontSize="28" Padding="10" />
Then, when one of your other TextBlocks is tapped, you can find it as follows:
// locate the parent stackpanel
var parentStackPanel = tappedTextBlock.Ancestors().First()
// locate the names TextBlock
var nameTextBlock = parentStackPanel.Elements()
.Where(el => el.Name == "NameText").Single();
Cast the sender in the GestureListenerHold method.