when i run program, listbox not show nothing.
please give me correct code.
<StackPanel x:Name="ContentPanel1" Grid.Row="1" Margin="12,0,12,0">
<ListBox x:Name="MultiList" FontSize="26" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=id}" Width="150"/>
<TextBlock Text="{Binding Path=project_id}"/>
<Button Click="Button_Click" Content="button"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBlock x:Name="txtDay" />
<TextBlock x:Name="txtTemp"/>
</StackPanel>
//-------------------------
phoneDBContext db = new phoneDBContext("Data Source='appdata:/phoneDB.sdf'; File Mode = Read Write;");
var q1 = from p in db.Projects
select p;
MultiList1.ItemsSource = q1.ToList();
Try without "Path=". Example: Text="{Binding id}"
I found the error. The first letter of each field has to be uppercase.
I wasted one week time on this problem.
It shows a bug in the IntelliSense editor of Microsoft Visual Studio 2013.
I hope Microsoft will correct this problem.
<TextBlock Text="{Binding Path=Id}" Width="150"/>
Related
I have a page in a Windows Phone 8 app where the user can link items to a group (n:1). The group is selected via the Toolkit ListPicker control. Under the ListPicker is a unlink button for removing the link from item to group.
<StackPanel x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<toolkit:ListPicker x:Name="GorupList"
Header="Background"
ExpansionMode="FullscreenOnly"
ItemsSource="{Binding}"
SelectionChanged="GroupList_SelectionChanged">
<toolkit:ListPicker.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" />
</DataTemplate>
</toolkit:ListPicker.ItemTemplate>
<toolkit:ListPicker.FullModeItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="16 21 0 20">
<TextBlock Text="{Binding Name}"
FontSize="43"
FontFamily="{StaticResource PhoneFontFamilyLight}"/>
</StackPanel>
</DataTemplate>
</toolkit:ListPicker.FullModeItemTemplate>
</toolkit:ListPicker>
<Button x:Name="UnlinkButton" Content="Unlink" Click="OnUnlink" />
</StackPanel>
If the usere unlinks a item from a group, I want to set the SelectedItem of the ListPicker to null (no group selected). Just setting SelectedItem to null or SelectedIndex to -1 does not work (Exception: set valid value...).
Does anybody have an idea for this issue?
//EDIT: I'm looking for a workaround, not compiling a my own ListPicker control.
How about dropping in an initial string value <System:String>Choose Item...</System:String> , which can also act as a prompt, then you can refer to it in code GorupList.SelectedIndex = 0; and subsequently ignore in your code behind when selected?
<StackPanel x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<toolkit:ListPicker x:Name="GorupList"
Header="Background"
SelectionChanged="GroupList_SelectionChanged">
<toolkit:ListPicker.FullModeItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="16 21 0 20">
<TextBlock Text="{Binding Name}"
FontSize="43"
FontFamily="{StaticResource PhoneFontFamilyLight}"/>
</StackPanel>
</DataTemplate>
</toolkit:ListPicker.FullModeItemTemplate>
<System:String>Choose Item...</System:String>
</toolkit:ListPicker>
<Button x:Name="UnlinkButton" Content="Unlink" Click="OnUnlink" />
</StackPanel>
Quite right: Could you grab this solution PhoneApp5 and see if it's more to your requirements? Then either you or I can post up the code (mine as is or yours improved).
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
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
I have a listbox that is showing a dynamic list of data that can grow. At the bottom of this listobx, once the user has scrolled through all the items, I want to show a piece of text. And sometimes, depending on the situation, it can be a button or another listbox. But, I want to learn how to put a textbox first. I tried searching forums and tried, Grid, StackPanel, ScrollViewer. Nothing seems to work. This code here, looks promising but I am not able to scroll with this: This must be a common UI, I would guess. Any help?
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="tasteePic" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="I'm Hungry" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
<ProgressBar Height="4" HorizontalAlignment="Left" Margin="10,10,0,0" Name="progressBar1" VerticalAlignment="Top" Width="460" />
</StackPanel>
<ScrollViewer Grid.Row="1" ScrollViewer.VerticalScrollBarVisibility="Visible">
<StackPanel Margin="12,17,0,28">
<ListBox Name="MenuItemListBox" VerticalAlignment="Top" SelectionChanged="MenuItemListBox_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image
Margin="4, 4, 4, 4"
Grid.Column="0"
delay:LowProfileImageLoader.UriSource="{Binding ThumbNailUrl}" />
<StackPanel>
<TextBlock Text="{Binding Name}" FontWeight="Bold" />
<TextBlock Text="{Binding BusinessName}" />
<TextBlock Text="{Binding Price}" />
<TextBlock Text="{Binding Neighborhood}" />
<TextBlock Text="{Binding City}" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBlock Text="Test" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
</ScrollViewer>
</Grid>
You can place your TextBox after the ItemsPresenter element of the ListBox by retemplating in Blend.
Here's a worked example.
How to add a Control at the end of Items of a ListBox (e.g. a "Load More" Button or Hyperlink)?
I have a listbox contains a datatemplate with Image and TextBlock control inside. I want to get the ImageControl out by first getting the Grid Container
<ListBox x:Name="NewsList" Margin="0,0,20,0" SelectionChanged="NewsList_SelectionChanged" />
<DataTemplate>
<Grid Width="400" Height="89">
<Image HorizontalAlignment="Left" Width="64" x:Name="ImageThumbnail" Height="64" VerticalAlignment="Top" Margin="0,10,0,0" Source="http://vnexpress.net/Files/Subject/3B/A2/3B/15/top.jpg"/>
<TextBlock Text="{Binding Title}" Margin="78,0,8,0" TextWrapping="Wrap" FontSize="26.667" Height="74" VerticalAlignment="Top"/>
</Grid>
</DataTemplate>
</ListBox>
for (int i = 0; i < feeds.Count; i++)
var containerItem = list.ItemContainerGenerator.ContainerFromIndex(i);
And when I set the NewsList.Items = Feeds with feeds.Count is more than 23, some of the containerItem is null. If it is less than 23, I never get a null container.
Does anyone know what is the cause and how I can fix it. If we can have another way to get the imageControl out
One thing I can see is that your xaml doesn't look right to me.
Shouldn't it look like this:
<ListBox x:Name="NewsList" Margin="0,0,20,0" SelectionChanged="NewsList_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Width="400" Height="89">
<Image HorizontalAlignment="Left" Width="64" x:Name="ImageThumbnail" Height="64" VerticalAlignment="Top" Margin="0,10,0,0" Source="http://vnexpress.net/Files/Subject/3B/A2/3B/15/top.jpg"/>
<TextBlock Text="{Binding Title}" Margin="78,0,8,0" TextWrapping="Wrap" FontSize="26.667" Height="74" VerticalAlignment="Top"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Beyond that I'm not sure if that will totally help you or not.
My answer is to write a new ImageConverter that we can put into the tag in the xaml file, I don't have to deal with VisualTree anymore, so it works