How to show list of items on button click? - windows-phone-8

I am developing windows phone app..
I am taking 1 button and on click of that button the dropdown list of clothes should come..
how to code for this?
Problem: How to take this list on button click

Your xaml should be :
<Button x:Name="BtnShowCloth" Content="showCloth" Margin="10,5" Click="BtnAddProduct_Click"/>
<toolkit:ListPicker ExpansionMode="FullScreenOnly" x:Name="ClothListPicker" Visibilty="Collapsed" Margin="0,0,0,10" Height="100" >
<toolkit:ListPicker.ItemTemplate>
<DataTemplate>
<TextBlock Style="{StaticResource AppTextBlockStyle}" Text="{Binding}"/>
</DataTemplate>
</toolkit:ListPicker.ItemTemplate>
<toolkit:ListPicker.FullModeItemTemplate>
<DataTemplate>
<TextBlock Style="{StaticResource AppTextBlockStyle}" Text="{Binding}" Margin="2,10,0,0" FontSize="31"/>
</DataTemplate>
</toolkit:ListPicker.FullModeItemTemplate>
</toolkit:ListPicker>
//Another way use ListBox Control
<ListBox Grid.Row="1" Name="ListBoxCloth" Height="50">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Style="{StaticResource AppTextBlockStyle}" Text="{Binding}" Margin="2,10,0,0" FontSize="31"/>
</DataTemplate>
<ListBox.ItemTemplate>
</ListBox>
Code Behind of button click fill list of cloth names. In windows phone no dropdown list exist, you should use longlistselector instead of dropdown
private void BtnAddProduct_Click(object sender, RoutedEventArgs e)
{
List<string> clothNameList = new List<string>();
clothNameList .Add("a");
clothNameList .Add("b");
clothNameList .Add("c");
clothNameList .Add("d");
clothNameList .Add("e");
//ClothListPicker.ItemsSource = clothNameList;
// ClothListPicker.Visibility = Visibility.visible;
ListBoxCloth.ItemsSource = clothNameList;
ListBoxCloth.Height = 400;
}

This is very broad question, infact does not fall in SO standards of Questions.
You should research and try something and ask only if you got stuck somewhere or if your method fails.
And to your question, it needs clarification on many things like
What is the format of your clothes data
Are you getting it from a web service or a local db or some other resource
Is it a single List or a groups of items etc
Hence, it becomes hard to answer. Please keep these things in mind, next time when asking questions.
Based on your comment:
You should split your task into multiple small tasks
First thing, learn how to fetch the data from your db
Converting that data into List of objects
Creating your UI for the data
Bind the data to the UI in your Button_Click event handler
Happy coding !!

Related

Search of user's contacts: highlight part of the name that matches with the search, when using Data Binding and LongListSelector (WP8)

I'm binding the user's contact list to a LongListSelector, as I saw in a Sample, this way:
<phone:PhoneApplicationPage.Resources>
...
<DataTemplate x:Key="AddrBookItemTemplate" >
<ListBoxItem>
<StackPanel>
<TextBlock Text="{Binding Path=DisplayName, Mode=OneWay}" FontFamily="Segoe WP" FontSize="25" />
<TextBlock Text="{Binding Path=PhoneNumbers[0].PhoneNumber, Mode=OneWay}" FontFamily="Segoe WP Light" FontSize="20" />
</StackPanel>
</ListBoxItem>
</DataTemplate>
...
</phone:PhoneApplicationPage.Resources>
...
<Grid x:Name="ContentPanel">
<phone:LongListSelector
x:Name="AddrBook"
JumpListStyle="{StaticResource AddrBookJumpListStyle}"
GroupHeaderTemplate="{StaticResource AddrBookGroupHeaderTemplate}"
ItemTemplate="{StaticResource AddrBookItemTemplate}"
LayoutMode="List"
IsGroupingEnabled="true"
HideEmptyGroups ="true"
SelectionChanged="AddrBook_SelectionChanged"/>
</Grid>
And I'm doing the user's search for a specific name this way (using LINQ):
contactsList = contactsEnum.Where(m => m.PhoneNumbers.Count() > 0 && (m.DisplayName.Split(' ').ToList().Any(p => p.ToLower().StartsWith(tbxSearch.Text.ToLower())) || (m.PhoneNumbers.Any(y => y.PhoneNumber.StartsWith(tbxSearch.Text))))).ToList();
AddrBook.ItemsSource = contactsList; // With IsGroupingEnabled=false
I'm looking for a way to highlight the part of the name that matches with the search, but I can't do this, with the way I made the data binding...
Does anyone know how I could do the highlight?
You could do something like this, whenever the word you type in within the textbox matches with the word which could be within the sub strings or the Collection, you could simply highlight it!
string[] substrings = regex.Split(Content.Text);
Content.Inlines.Clear();
foreach (var item in substrings)
{
//if a word from the content matches the search-term
if (regex.Match(item).Success)
{
//create a 'Run' and add it to the TextBlock
Run run = new Run(item);
run.Foreground = Brushes.Red;
Content.Inlines.Add(run);
}
else //if no match, just add the text again
Content.Inlines.Add(item);
}
References: Is there a way I can highlight specific text in a textbox?
How to Highlight the result from context sensitive search in windows phone 7?

selecting a value from a ListPicker in windows phone 8

can any one please explain a simple way to select a value from a listpicker control and under what event its best to select the value, apart from SelectionChanged event in windows phone 8 ?
For that you could do something like this:
Assume this is your ListPicker in your xaml:
<toolkit:ListPicker.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding name}" Visibility="Collapsed"/>
</DataTemplate>
</toolkit:ListPicker.ItemTemplate>
<toolkit:ListPicker.FullModeItemTemplate>
<DataTemplate>
<TextBlock>
<Run Text="{Binding name}"/>
</TextBlock>
</DataTemplate>
</toolkit:ListPicker.FullModeItemTemplate>
Then in your code:
var filterdata = e.Result;
var filtervalue = JsonConvert.DeserializeObject<List<filterdatas>>(filterdata);//filterdatas is just the name of the list which you're displaying
filterpicker.ItemsSource = filtervalue;
Within your SelectionChanged event handler, you could something like this to get the values:
if(filterpicker.SelectedItem == null) //here filterpicker is the name of the `ListPicker`
return;
filterdatas element = filterpicker.SelectedItem as filterdatas;
MessageBox.Show("This is the id:"+element.id);//here the id of the selected item is being retrieved
For more you could refer here:
How to Get the Selected Item of a ListPicker
Hope it helps!
I have used this code in my Project and it works great.
strListPickerValue = ((ListPickerItem)lpRemind.SelectedItem).Content.ToString();
here lpRemind is the listPicket.

Display Tooltip on Tapping the pushpin(Custom marker) in Windows Phone 8 Map

In a Windows Phone map I am drawing my mapmarker and using them as pushpin.
MapLayer mapLayer = new MapLayer();
foreach (LocationDetail locationDetail in locationListobj)
{
MapOverlay overlay = new MapOverlay();
overlay.Content = GetImage(locationDetail);
overlay.GeoCoordinate = new GeoCoordinate(locationDetail.Latitude, locationDetail.Longitude);
overlay.PositionOrigin = new Point(0.0, 1.0);
mapLayer.Add(overlay);
}
AllyMap.Layers.Add(mapLayer);
A new requirement came up that upon tapping on the map we have to show the description in a infobar. Can anybody please help me how could I do that.
You need to set the ToolTipService.ToolTip property on the PushpinViewModel which should be a UIElement. ToolTips must be hooked up to a UIElement, which actually renders in your visual tree, to be triggered by mouse hover. Hovering is just a way of showing the tooltip.
<ToolTipService.ToolTip>
<ToolTip Style="{StaticResource ToolTipStyle}">
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding Title}" />
<TextBlock Text="{Binding Description}" TextWrapping="Wrap" />
</StackPanel>
</ToolTip>
</ToolTipService.ToolTip>
You could refer this for more:
http://social.technet.microsoft.com/wiki/contents/articles/24118.windows-phone-8-maps-api-making-custom-pushpin-with-custom-tooltip-c-xaml.aspx
Hope it helps!

Tile and longlistselector itemTemplate

I would like to to create an itemtemplate of longlistselector using a tile
is it possible?
how to do it in xaml?
could someone show me some code to do it?
Using a longlistselector is very easy for this tile applications.
<phone:PhoneApplicationPage.Resources>
<DataTemplate x:Key="TileDataTemplate">
<Grid Background="{StaticResource PhoneAccentBrush}"
Margin="0,0,12,12">
<StackPanel VerticalAlignment="Top">
<TextBlock Text="{Binding Content}" TextWrapping="Wrap"/>
</StackPanel>
<StackPanel VerticalAlignment="Bottom">
<TextBlock Text="{Binding Title}" Margin="6,0,0,6"/>
</StackPanel>
</Grid>
</DataTemplate>
</phone:PhoneApplicationPage.Resources>
<phone:LongListSelector Margin="0,0,-12,0"
SelectionChanged="LongListSelector_SelectionChanged"
LayoutMode="Grid"
GridCellSize="150,150"
ItemsSource="{Binding DataBindingItems}"
ItemTemplate="{StaticResource TileDataTemplate}"
/>
here the most important thing note is the LayoutMode="Grid" GridCellSize="150,150" properties.
Edit:::
I have added the code for the tile where i would show up a tile with two textblocks showing up some content on top and then title in the end. The way you have to wire up some sample data or dynamic depends on code behind. Ping me if that is needed. And this is really basic stuff. Accept if you get the answer.
// find the tile object for the application tile that using "flip" contains string in it.
ShellTile oTile = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("flip".ToString()));
if (oTile != null && oTile.NavigationUri.ToString().Contains("flip"))
{
FlipTileData oFliptile = new FlipTileData();
oFliptile.Title = "Hello WP8!!";
oFliptile.Count = 11;
oFliptile.BackTitle = "Updated Flip Tile";
oFliptile.BackContent = "back of tile";
oFliptile.WideBackContent = "back of the wide tile";
oFliptile.SmallBackgroundImage = new Uri("Assets/Tiles/Flip/159x159.png", UriKind.Relative);
oFliptile.BackgroundImage = new Uri("Assets/Tiles/Flip/336x336.png", UriKind.Relative);
oFliptile.WideBackgroundImage = new Uri("Assets/Tiles/Flip/691x336.png", UriKind.Relative);
oFliptile.BackBackgroundImage = new Uri("/Assets/Tiles/Flip/A336.png", UriKind.Relative);
oFliptile.WideBackBackgroundImage = new Uri("/Assets/Tiles/Flip/A691.png", UriKind.Relative);
oTile.Update(oFliptile);
MessageBox.Show("Flip Tile Data successfully update.");
}
else
{
// once it is created flip tile
Uri tileUri = new Uri("/MainPage.xaml?tile=flip", UriKind.Relative);
ShellTileData tileData = this.CreateFlipTileData();
ShellTile.Create(tileUri, tileData, true);
}

SemanticZoom - How do I keep two ListView controls in selection synch?

Using a SemanticZoom control in an MVVM project, I have two ListView controls with custom styles and panels, etc. so they display horizontally, there is no grouping or need for it.
I bind both to a CollectionViewSource in the view model.
When I click an item in the zoomed-out view, it doesn't take focus to that item in the zoomed-in view.
How can I achieve this?
Edit
Added XAML code:
<SemanticZoom>
<SemanticZoom.ZoomedInView>
<ListView
Style="{StaticResource HorizontalListViewStyle}"
SelectionMode="None"
ScrollViewer.IsHorizontalScrollChainingEnabled="False"
ItemsSource="{Binding BoardItems}"
ItemContainerStyle="{StaticResource ZoomedOutListViewItemContainerStyle}">
</ListView>
</SemanticZoom.ZoomedInView>
<SemanticZoom.ZoomedOutView>
<ListView x:Name="listView"
Style="{StaticResource HorizontalListViewStyle}"
SelectionMode="None"
ScrollViewer.IsHorizontalScrollChainingEnabled="False"
ItemsSource="{Binding BoardItems}"
ItemContainerStyle="{StaticResource ZoomedOutListViewItemContainerStyle}">
</ListView>
</SemanticZoom.ZoomedOutView>
</SemanticZoom>
Both of your ZoomedInView and ZoomedOutView need to have ScrollViewer.IsHorizontalScrollChainingEnabled="False" in order to scroll properly.
In codebehind for the page (or using an attached property), handle the ViewChangeStarted event with this code:
private void zoomyThingWoo_ViewChangeStarted(object sender, SemanticZoomViewChangedEventArgs e)
{
if (e.SourceItem.Item != null)
{
e.DestinationItem.Item = e.SourceItem.Item;
}
}
That's it. The documentation makes it sound like SemanticZoom will just work with any two controls that implement ISemanticZoomInfo but it doesn't.
I raised a documentation bug with the XAML team in Redmond.