Combo box in windows phone 8 - c#

<ComboBox x:Name="c1" Margin="21,134,228,-184" BorderBrush="{x:Null}" BorderThickness="6" Background="{x:Null}" Foreground="#FFFF0017" />
List<String> source = new List<String>();
c1.ItemsSource = source;
c1.SelectedIndex = 0;
I can see the items but I can't select them? and I can't scroll??? like when I add more than the size of the combo box,
it should appear a scroll? I'm coming from windows store c# and that is the way it is over there.
I want it to make it work just as a regular combobox, you click on it and it will appear a scrollable list of items that you can select... Thanks!

It is not recommended to use combobox control. Use the ListPicker Control.
Steps :
Download the nuget package from this link: https://www.nuget.org/packages/WPtoolkit/
Add a reference to the top of your xaml file :
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
Use ListPicker as shown below :
<toolkit:ListPicker Height="50" ScrollViewer.VerticalScrollBarVisibility="Auto" ItemsSource="{Binding ElementName=ConverterPage, Path=Locations}" Margin="179,129,70,434" Name="cmbCurrFrom">
<toolkit:ListPicker.ItemTemplate>
<DataTemplate>
<TextBlock FontSize="30" Foreground="Black" Text="{Binding Path=Location}"></TextBlock>
</DataTemplate>
</toolkit:ListPicker.ItemTemplate>
<toolkit:ListPicker.FullModeItemTemplate>
<DataTemplate>
<TextBlock FontSize="30" Foreground="Black" Text="{Binding Path=Location}"></TextBlock>
</DataTemplate>
</toolkit:ListPicker.FullModeItemTemplate>
</toolkit:ListPicker>

Related

Move data from itemsource of one listbox to another listbox wp8

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.

How to access checkbox value from a listbox in windows phone

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;

WP8 Can't show listbox item after using hardware back button

I have two ListBox items: one for show all items and another ListBox for show only selected item and now when I am using hardware back button second ListBox item is not showing?
What do I need to do to allow the ListBox to be selectable/clickable upon return?
Height="72" TextWrapping="Wrap" Name="txtMSG" Text="TextBox" Width="456"/>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="2" Margin="15,10,15,0">
<ListBox Name="list_location" Tap="list_location_Tap" Foreground="Black">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock x:Name="item_name" Text="{Binding description, Mode=OneWay}" Padding="5,15,5,15" TextWrapping="Wrap" FontSize="{StaticResource PhoneFontSizeLarge}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<ListBox Name="list_locationAdd" Foreground="Black" Visibility="Collapsed">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock x:Name="item_name" Text="{Binding description, Mode=OneWay}" Padding="5,15,5,15" TextWrapping="Wrap" FontSize="{StaticResource PhoneFontSizeLarge}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
list_locationAdd.Visibility = Visibility.Visible;
list_location.Visibility = Visibility.Collapsed;
if (!list_locationAdd.Items.Contains(list_location.SelectedItem))
{
list_locationAdd.Items.Add(list_location.SelectedItem);
}
Create XML document and save it to your phone using StorageFile class. Everytime you open your app, it will on launch check your xml file and populate the datagrid. So when you make changes to listboxes it should make changes to xml file too. Next time you quit your application and launch it again, reads data from xml file and then it has the data as it was last time. So my answer is: save your data on phone with xml file.
Save data to phone: https://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.storagefile.aspx
Handling XML documents and elements: https://msdn.microsoft.com/en-us/library/system.xml.linq.xdocument%28v=vs.110%29.aspx

TiltEffect on longListSelector Items, windows phone 8

This may sound really NOOBI!
I have a LongListSelector for showing some items in my app, and I wanted to add this cool effect called TiltEffect to the items so they show some interaction as user taps on one of the them.
For that matter I searched the internet and came up with this link on MSDN and I have done as instructed there. I downloaded the code sample, added the discussed class to my project and in the MainPage.xaml I added the following lines:
xmlns:local="clr-namespace:MyNamespace"
local:TiltEffect.IsTiltEnabled="True"
alnd also in the class TiltEffect.cs I added LongListSelector as a TiltableItem like this:
static TiltEffect()
{
// The tiltable items list.
TiltableItems = new List<Type>() { typeof(ButtonBase), typeof(ListBoxItem), typeof(LongListSelector),};
UseLogarithmicEase = false;
}
Now the problem is that when any of the items on the LongListSelector is tapped, the whole LongListSelector tilts instead of only the tapped item.
please help!
I found the answer to my problem here
I wrapped my DataTempalte in a ListBoxItem, now it looks like this:
<phone:LongListSelector x:Name="MyLongListSelector"
Margin="0,0,0,0"
ItemsSource="{Binding My_Items}"
SelectionChanged="MyLongListSelector_SelectionChanged">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<ListBoxItem >
<StackPanel Margin="0,0,0,7" local:TiltEffect.IsTiltEnabled="True" MinWidth="460">
<StackPanel.Background>
<ImageBrush Stretch="Fill" ImageSource="/Assets/Photos/items.png"/>
</StackPanel.Background>
<TextBlock Text="{Binding Title}"
TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"
TextAlignment="Center"
Margin="0, 5, 0, 15" FontFamily="Assets/Fonts/BNazanin.ttf#B Nazanin"/>
</StackPanel>
</ListBoxItem>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
could you try adding type that you used as a jumplist item to The tiltable items Collection instead of LongListSelector.

Ungrouped Long List Selector

Okay, So I am trying to bind a list of objects with a DisplayName property to a long list selector.
XAML Code
<phone:LongListSelector x:Name="lls_TemplateFields" HorizontalAlignment="Left" Width="450" Grid.Row="2" Height="400" LayoutMode="List" Background="#FF9E9D9D" IsGroupingEnabled="False">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<Grid>
<TextBlock Text="{Binding DisplayName}" Foreground="Black" FontSize="24"/>
</Grid>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
C# Code
List<AttributeDefinition> m_SelectedAttributes = new List<AttributeDefinition>();
lls_TemplateFields.ItemsSource = m_SelectedAttributes;
My Class AttributeDefinition contains a property for DisplayName. If I group the the list using a group key then the list will show up, however I cannot get just a plain list of items to show up. Like a listbox in WPF C#.
I am using this list to represent a list of chosen AttributeDefinitions from another list that shows all the AttributeDefinitions grouped alphabetically by their DisplayName property, and the Display Value is Binded to the DisplayName Property like shown below...
XAML
<phone:LongListSelector x:Name="lls_AttributeList" HorizontalAlignment="Left" Height="450" VerticalAlignment="Top" Width="450" HideEmptyGroups="True" IsGroupingEnabled="True" SelectionChanged="SelectionChanged">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<Grid>
<Border BorderThickness="2">
<TextBlock Text="{Binding DisplayName}" Foreground="{StaticResource PhoneChromeBrush}" FontSize="24"/>
</Border>
</Grid>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
<phone:LongListSelector.GroupHeaderTemplate>
<DataTemplate>
<Grid Width="50" Height="50" HorizontalAlignment="Left" VerticalAlignment="Center" Background="Blue">
<Border BorderThickness="4">
<TextBlock Text="{Binding Key}" Foreground="White" FontSize="38" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
</Grid>
</DataTemplate>
</phone:LongListSelector.GroupHeaderTemplate>
</phone:LongListSelector>
C#
List<AttributeKeyGroup<AttributeDefinition>> DataSource = AttributeKeyGroup<AttributeDefinition>.CreateGroups(AttributeData,
Thread.CurrentThread.CurrentUICulture,
(AttributeDefinition aDef) => { return aDef.Type; },
true);
lls_AttributeList.ItemsSource = DataSource;
This list works just fine. And the data in the background is functioning properly, because as I select items from the total list of attributedefinitions they are removed from the LongListSelector and added to the LongListSelector of the selected lists Itemssource
For further inquiry into more code surrounding this User Control please feel free to ask I will disclose as much code as I can without breaking my non-disclosure agreement with my work. Thank you for taking the time to read and possibly help. Much appreciated.
List<AttributeDefinition> m_SelectedAttributes = new List<AttributeDefinition>();
lls_TemplateFields.ItemsSource = m_SelectedAttributes;
because you just instantiated this list and binding it right away? How about adding some items into the list
There are two answers to this. I have tried both and both work.
[1] You have to set the LongListSelector.ScrollTo(object) to the first object of your list when you update the data if the list has 1 or more items. Such as...
lls_TemplateFields.ItemsSource = m_SelectedAttributes;
if(m_SelectedAttributes.Count > 0)
{
lls_TemplateFields.ScrollTo(m_SelectedAttributes[0]);
}
[2] The proper way to fix this is to use ObservableCollections which work better with DataBinding and the WP8 WPF SDK UI to update on adding objects to the ObservableCollection.
ObservableCollection<AttributeDefinition> m_SelectedAttributes =
new ObservableCollection<AttributeDefinition>();
lls_TemplateFields.ItemsSource = m_SelectedAttributes

Categories

Resources