Which control to use in Windows Phone 7 so i can display data from a webservice - windows-phone-7

i'm new to windows phone 7 and i have a webservice which returns data from a sql database.
I'm display the data in a gridview in asp.net.
Now i want to make the same in windows phone 7
Which control to use to show the records and how?
Thank you very much

There is no out of the box datagrid control on windows phone 7.
This is because it is really hard to got a lot of data in a grid readable on a small screen as a phone. If you want to have this anyway you have to build your own.
You can use a listbox as some soft of grid like this:
<ListBox x:Name="myListBox">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock width="100" Text="{Binding Field1}"/>
<TextBlock width="100" Text="{Binding Field2}"/>
<TextBlock width="100" Text="{Binding Field3}"/>
<TextBlock width="100" Text="{Binding Field4}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
If this isn't what you're looking for you could maybe have a look at one of the following links:
http://www.silverlightshow.net/items/Building-a-DataGrid-Control-for-Silverlight-for-Windows-Phone-Part-1.aspx
WpfToolkit DataGrid does not work in Windows Phone 7

ListBox with custom DataTempale is what you looking for.
First of all, download data from the server and put it into some collection. ObservableCollection is a best choice, because it's automatically update view when you add/remove new items. So, code snipped will be like this:
ObservableCollection<CustomItem> items = new ObservableCollection<CustomItem>();
// add items to the `items` list
list.ItemsSource = items; // bind items to the ListBox with a name 'list'
Xaml:
<ListBox x:Name="list">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDifenition Width="Auto" />
<ColumnDifenition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text={Binding Field1} />
<TextBlock Grid.Column="1" Text={Binding Field1} />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

Related

Windows Phone 8 Panaroma Application Tile Title

I am trying to write on panaroma application in tile image title.
And I can not see like a below code in .xaml page;
<image Title="blabla" ...>
This is my code;
<phone:PanoramaItem Header="Kişisel Bilgiler" Orientation="Horizontal">
<!--Double wide Panorama with large image placeholders-->
<Grid>
<StackPanel Margin="0,4,16,0" Orientation="Vertical" VerticalAlignment="Top">
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal" Margin="0,12,0,0">
<toolkit:WrapPanel>
<Border BorderBrush="AliceBlue" BorderThickness="1" Margin="12,0,0,0">
<Image Width="173" Height="173" Source=".\Assets\cinsiyet.png" Tag="img_deneme" Margin="0,0,0,0" x:Name="img_cins" MouseEnter="Image_MouseEnter" />
</Border>
</toolkit:WrapPanel>
</StackPanel>
</StackPanel>
</Grid>
</phone:PanoramaItem>
But I want to
Thank is advance.
(Sorry my language)
Image control doesn't have any property to display text similar to Tile's title. You need to add other control to display the title, for example using TextBlock :
<toolkit:WrapPanel>
<Grid>
<Border BorderBrush="AliceBlue" BorderThickness="1" Margin="12,0,0,0">
<Image Width="173" Height="173" Source=".\Assets\cinsiyet.png" Tag="img_deneme" Margin="0,0,0,0" x:Name="img_cins" MouseEnter="Image_MouseEnter" />
</Border>
<TextBlock Margin="0,150,0,0" Text="Tile Title" Foreground="White"/>
</Grid>
</toolkit:WrapPanel>
You may also want to try HubTile control as an alternative.

Drag&Drop ListBox Items out of the LisBox Windows Phone 8

I have a sample data bounded to the listbox datatemplate and each item has a MouseDragElementBehavior with ConstrainToParentBounds false. I want to dragging any item in the listbox to any space in the page. However, Items are still bounded to the Listbox. Any Suggestions? AllowDrop property does not work on Windows Phone.
<ListBox x:Name="countryName" HorizontalAlignment="Left" Height="361" Margin="10,10,0,0" VerticalAlignment="Top" Width="436">
<i:Interaction.Behaviors>
<el:MouseDragElementBehavior ConstrainToParentBounds="False"/>
</i:Interaction.Behaviors>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Name}">
</TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

Binding to a Collection of Checkboxes

I'm trying to do some XAML binding for the Windows Phone (targeting WP7.1) and I have a collection of checkboxes that I want to display. I want to put them inside the WrapPanel
What control(s) would I use to bind to a collection of checkboxes? I don't see an ItemSource for the WrapPanel. So I'm not sure what I would use.
<ListBox Height="auto" Name="lbAssignments" BorderThickness="1" BorderBrush="Black" ItemsSource="{Binding DataList}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<TextBlock x:Name="TextBlock" Text="{Binding Title}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="10,0,0,10" FontSize="26.667" TextWrapping="Wrap"/>
<TextBlock x:Name="TextBlock1" Text="{Binding Title}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="10,0,0,10" FontSize="26.667" TextWrapping="Wrap"/>
<toolkit:WrapPanel Height="400" Width="400">
<!--collection of checkboxes-->
</toolkit:WrapPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Binding to a collection of UI controls is not exactly the thing you'd want to do. Instead, I would recommend binding to a collection. For many reasons - performance, memory allocation and general maintenance/flexibility.
Since you mentioned that you have a List<string>, you can just bind it to a ListBox:
<ListBox ItemsSource="{Binding YourList}">
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox Content="{Binding}"></CheckBox>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
However, you can still proceed with biding an element to a collection of other elements, given that appropriate support exists. You could use an ItemsControl:
<ItemsControl ItemsSource="{Binding ElementName=myPage, Path=SomeCollection}">
</ItemsControl>
Here, SomeCollection might as well be ObservableCollection<CheckBox>.

Windows Phone 7 - dynamic items for a ListBox

I want to create the content of the each item inside a ListBox dynamically - think of it as a list of items. Or think of a phone book application with contacts and each contact has one or more phone numbers that are displayed beneath the name; the name is one field, the phone numbers is a second field. But the content of the phone number field would obviously depend on the number of phone number the contact has.
Like:
Andrew Adams <-- TextBlock for name
650-123-2222 <-- "Item" for numbers
490-222-3333
Benny Benjamin
650-123-3333
I have tried to solve this by creating a second ListBox for the numbers item inside the main ListBox item. But I don't know how I can populate this second ListBox with a model from C#.
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<StackPanel Height="Auto" Width="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
<ListBox Name="ContactResultsData" ItemsSource="{Binding Contacts}" Margin="24,0" Height="620">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Name="ContactName" Text="{Binding ContactName}" Style="{StaticResource PhoneTextLargeStyle}" />
<ListBox Name="NumbersList" ItemsSource="{Binding NumbersList}">
<TextBlock Name="Number" Text="{Binding Number}" Style="{StaticResource PhoneTextSmallStyle}" />
</ListBox>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</Grid>
</Grid>
Question would be: How can I set NumbersList ItemsSource from C#? Or can I solve my problem with some other better approach?
You need to set the ItemTemplate for your second ListBox. It should look like:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<StackPanel Height="Auto" Width="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
<ListBox Name="ContactResultsData" ItemsSource="{Binding Contacts}" Margin="24,0" Height="620">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Name="ContactName" Text="{Binding ContactName}" Style="{StaticResource PhoneTextLargeStyle}" />
<ListBox Name="NumbersList" ItemsSource="{Binding NumbersList}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Name="Number" Text="{Binding Number}" Style="{StaticResource PhoneTextSmallStyle}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</Grid>
On a side note, don't give your UI elements name (Name or x:Name) unless you need to use them in code behind or from xaml. This is especially true for items within an ItemTemplate.
The inner can't directly contain a
If NumbersList is an IList or similar, then you can't bind to "Number" - simply use {Binding} instead

ListBox Style Selected item on windows phone

i would like know how can i add a style when a item of the listbox is selected.
I have the following listbox:
<ListBox x:Name="ListBoxDays"
VerticalAlignment="Top"
ItemTemplate="{StaticResource WeekDayTemplate}"
ItemsSource="{Binding WeekDayList}" />
And i also have a DataTemplate to the listbox.
<phone:PhoneApplicationPage.Resources>
<DataTemplate x:Key="WeekDayTemplate">
<StackPanel x:Name="stackPanel" Orientation="Horizontal" Width="400" Margin="12,0,0,10" Height="100" >
<StackPanel VerticalAlignment="Center" Orientation="Vertical">
<TextBlock Text="{Binding WeekDayName}" Style="{StaticResource PhoneTextExtraLargeStyle}" TextWrapping="Wrap" TextTrimming="WordEllipsis" Foreground="{StaticResource PhoneRadioCheckBoxPressedBorderBrush}" UseLayoutRounding="True" />
<TextBlock Text="{Binding ShortDate}" Style="{StaticResource PhoneTextTitle2Style}" TextWrapping="Wrap" TextTrimming="WordEllipsis" Foreground="{StaticResource PhoneBorderBrush}" Margin="25,0,12,0" />
</StackPanel>
</StackPanel>
</DataTemplate>
</phone:PhoneApplicationPage.Resources>
At the moment when i select an item of the listbox no color change happens.
You have to change the style of the template ListBoxItem which the ListBox generates for each of the items that it renders. Your updated template needs to customise the Selected visual state. You can then associate this new template with your ListBox via the ListBox.ItemContainerStyle property.
There is a good tutorial, with sourcecode to download, here:
http://windowsphonegeek.com/tips/How-to-customize-the-WP7-ListBox-Selected-Item--Part1-Control-Template

Resources