How i can bind two list box item source in single page Windows Phone? I mean:
Case 1: I have a json url and I get a response and so in listbox is ok
Case 2: When a user will tap the selected item and I have one more json url, the response will show on same page inside of selected item.
<ListBox Name="list_contact" ItemsSource="{Binding}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10*" />
</Grid.ColumnDefinitions>
<StackPanel>
<TextBlock x:Name="ContactResults" Foreground="Red" Text="{Binding service_name, Mode=OneWay}" FontSize="{StaticResource PhoneFontSizeLarge}" Margin="10, 0, 0, 0" />
</StackPanel>
<StackPanel>
<TextBlock x:Name="ContactResult" Foreground="Red" Text="{Binding fname , Mode=OneWay}" FontSize="{StaticResource PhoneFontSizeLarge}" Margin="10, 20, 0, 0" />
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Related
I want to display the default message when list box is empty and for same I used following code but this code is not working :
<HubSection x:Name="PivotFromAccount" Style="{StaticResource HubSectionStyle2}" >
<DataTemplate>
<Border Style="{StaticResource brdhubsectionstyle}">
<Grid Grid.Row="1" Style="{StaticResource GridMainStyleHubSession}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Border Style="{StaticResource brdheaderstyle}">
<TextBlock Text="From Account" Style="{StaticResource lblheaderstyle}" />
</Border>
<ListBox x:Name="lstAccountDetailsfrom" Grid.Row="1" ItemsSource="{Binding }"
Style="{StaticResource LstBoxStyleBranches}"
Tapped="lstAccountDetailsfrom_Tapped"
ItemContainerStyle="{StaticResource lstAccountliststyle}"
ItemTemplate="{StaticResource lstAccountlistDataTemplate}" >
</ListBox>
<TextBlock Margin="4" FontStyle="Italic" FontSize="12" Text="List is empty" x:Name="txtmessage" Grid.Row="1" Foreground="Black" />
<i:Interaction.Behaviors>
<ic:DataTriggerBehavior Binding="{Binding ElementName=lstAccountDetailsfrom, Path=Items.Count,Converter={StaticResource DataTriggerBehavior},Mode=TwoWay}" Value="0" ComparisonCondition="GreaterThan">
<ic:ChangePropertyAction TargetObject="{Binding ElementName=txtmessage}" PropertyName="Visibility" Value="Collapsed"/>
</ic:DataTriggerBehavior>
</i:Interaction.Behaviors>
</Grid>
</Border>
</DataTemplate>
</HubSection>
I tried with the Ivalue converter also like below but it is also not much more helpful. It is always sending 0 count to ValueConverter
<TextBlock Margin="4" FontStyle="Italic" FontSize="12" Text="List is empty" x:Name="txtmessage" Grid.Row="1" Foreground="Black" Visibility="{Binding ElementName=lstAccountDetailsfrom,Converter={StaticResource DataTriggerBehavior},Mode=TwoWay}" />
If your data source is an ObservableCollection you can bind to its Count property with a custom IValueConverter than converts 0 to Visible and 1 to Collapsed and use it on the TextBlock. No behavior needed.
I have a scrollviewer with an item template on it. the user sends a control number and I need to scroll to that item. How can I find the offset for the scrollviewer?
here is the scrollviewer that I am using
<ScrollViewer Grid.Row="0" x:Name="ScrollPanel" Padding="0">
<Grid x:Name="TestPanel" >
<ItemsControl x:Name="MainItemsControl" ItemsSource="{Binding PostList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel x:Name="PostPanel" Margin="0,5,0,5">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="60" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Image x:Name="IconUrl" Source="{Binding IconUrl}" Grid.Row="0" Grid.Column="0" Margin="12,0,12,0" VerticalAlignment="Center" HorizontalAlignment="Center" Width="50"/>
<StackPanel Grid.Row="0" Grid.Column="1">
<TextBlock x:Name="PostAuthorName" Text="{Binding PostAuthorName}" TextWrapping="NoWrap" Margin="12,0,12,0" Foreground="Black" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PostTime" Text="{Binding PostTime}" TextWrapping="NoWrap" Margin="12,0,12,0" Foreground="Black" Style="{StaticResource PhoneTextSubtleStyle}"/>
</StackPanel>
<TextBlock x:Name="ReplyNumber" Text="{Binding ReplyNumber}" Grid.Row="0" Grid.Column="2" TextWrapping="NoWrap" Foreground="Black" Margin="12,0,12,0" Style="{StaticResource PhoneTextNormalStyle}" VerticalAlignment="Center"/>
</Grid>
<RichTextBox x:Name="PostContent" localcontrols:Properties.BBCode="{Binding PostContent}" />
<Rectangle Grid.Row="1" Fill="Gray" Height="1" HorizontalAlignment="Stretch" Margin="0,10,0,10"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</ScrollViewer>
The offset can be calculated in this way. The code is adopted from this answer.
void ScrollToIndex(int index)
{
var itemContainer = MainItemsControl.ItemContainerGenerator.ContainerFromIndex(index) as UIElement;
GeneralTransform transform = itemContainer.TransformToVisual(ScrollPanel);
Point position = transform.Transform(new Point(0, 0));
ScrollPanel.ScrollToVerticalOffset(position.Y);
}
The ItemsControl does not implement logic that allows scrolling to a particular item. You can use the ListBox control instead. This control has a ScrollIntoView method that accepts the object you would like to scroll to as an argument. You can still use the RadWrapPanel by setting the ItemsPanel property of the ListBox control.
You don't have properties, but you have two methods for this: ScrollToVerticalOffset (to scroll vertically) and ScrollToHorizontalOffset (to scroll horizontally).
this.scrollViewer2.ScrollToVerticalOffset(0);
I have a checkbox inside a stackpanel inside a listbox. I need to set the visibility of that checkbox based on some logical operations, so I need to find that element in listbox.
I am using the following code to find the checkbox on my PageLoad, after the list`s dataSource has been set.
But on this listboxItem i get a null value and a exception saying : reference is not a valid visual dependencyobject
private void searchListCheckBoxVisibility()
//private void SearchList_Loaded(object sender, RoutedEventArgs e)
{
try
{
ListBoxItem listItem = this.SearchList.ItemContainerGenerator.ContainerFromIndex(2) as ListBoxItem;
CheckBox targetCheckBox = FindFirstElementInVisualTree<CheckBox>(listItem);
}
}
The following is my xaml :
Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<ListBox Margin="13,10,7,10" x:Name="SearchList" DoubleTap="SearchList_DoubleTap">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel x:Name="searchListPanel" Orientation="Horizontal" Width="400" ScrollViewer.HorizontalScrollBarVisibility="Auto">
<StackPanel Orientation="Vertical" Width="340">
<StackPanel Orientation="Vertical">
<TextBlock Text="Name : " FontWeight="Bold" Style="{StaticResource ResourceKey=MSFTGuidelines_TextBlock}"/>
<TextBlock Text="{Binding User}" TextWrapping="Wrap" Style="{StaticResource ResourceKey=MSFTGuidelines_TextBlock}"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Project : " FontWeight="Bold" Style="{StaticResource ResourceKey=MSFTGuidelines_TextBlock}"/>
<TextBlock Text="{Binding Project}" TextWrapping="Wrap" Style="{StaticResource ResourceKey=MSFTGuidelines_TextBlock}"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Status : " FontWeight="Bold" Style="{StaticResource ResourceKey=MSFTGuidelines_TextBlock}"/>
<TextBlock Text="{Binding On_OffBoarded}" TextWrapping="Wrap" Style="{StaticResource ResourceKey=MSFTGuidelines_TextBlock}"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Date : " FontWeight="Bold" Style="{StaticResource ResourceKey=MSFTGuidelines_TextBlock}"/>
<TextBlock Text="{Binding DT_On_OffBoarded}" TextWrapping="Wrap" Style="{StaticResource ResourceKey=MSFTGuidelines_TextBlock}"/>
</StackPanel>
<StackPanel>
<TextBlock Text=""/>
</StackPanel>
</StackPanel>
<CheckBox Width="60"
x:Name="user_Checkbox"
Content="" Tag="{Binding ID}"
Visibility="Collapsed"
Checked="user_Checkbox_Checked"
Unchecked="user_Checkbox_UnChecked"
Style="{StaticResource ResourceKey=MSFTGuidelinesCheckBox}"
IsChecked="False"
/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
I am stuck at this issue for a while, and it has been getting onto my nerves now, Please help.
Thanks in advance.
You could simply use the VisualTreeHelper to find a control within your Listbox data template.
Reference: How to access a specific item in a Listbox with DataTemplate?
I have the follwing listpicker
<toolkit:ListPicker ItemsSource="{Binding title}" Name="titlePicker" ExpansionMode="ExpansionAllowed" Grid.Row="1" Margin="0,-50,50,0" Background="White" Foreground="#FFDA3434" Canvas.ZIndex="10" HorizontalAlignment="Right" FontSize="20" Grid.RowSpan="2"/>
that contains 3 items and i would like them to align right, but for some reason i can't find the option to align the text, what am i missing?
You should do this in the ListPickerItemTemplate. Add Template to the page resources (or app resources)
<phone:PhoneApplicationPage.Resources>
<DataTemplate x:Name="ListPickerItemTemplate">
<StackPanel Orientation="Horizontal">
<TextBlock HorizontalAlignment="Right" Text="{Binding ItemName}"/>
</StackPanel>
</DataTemplate>
<DataTemplate x:Name="ListPickerFullModeItemTemplate">
<StackPanel Orientation="Horizontal">
<TextBlock HorizontalAlignment="Right" Text="{Binding ItemName}"/>
</StackPanel>
</DataTemplate>
</phone:PhoneApplicationPage.Resources>
and assign template to the picker:
<toolkit:ListPicker
ItemTemplate="{StaticResource ListPickerItemTemplate}"
FullModeItemTemplate="{StaticResource ListPickerFullModeItemTemplate}"
...
<StackPanel x:Name="LayoutRoot" Background="Transparent" >
<TextBlock Margin="20,20,0,0" Text="Type Text Here" HorizontalAlignment="Left"/>
<TextBox x:Name="SearchTextBox" IsReadOnly="False" HorizontalAlignment="Left" Margin="20,5,0,0" Height="70" Width="400" dp:TextBoxOnTextChangedDependency.UpdateSourceOnChange="True" Text="{Binding SearchBoxText, Mode=TwoWay}" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="TextChanged">
<cmd:EventToCommand PassEventArgsToCommand="True"
Command="{Binding ElementName=SearchTextBox, Path=DataContext.SearchTextBox_TextChangedCommand}"
/>
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBox>
<Grid x:Name="LayoutList" Background="{StaticResource PhoneChromeBrush}">
<toolkit:LongListMultiSelector x:Name="treksLocationItems" Background="Transparent"
ItemsSource="{Binding Path=TreksLocationItems}">
<toolkit:LongListMultiSelector.ItemTemplate>
<DataTemplate>
<Grid Margin="0,5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image Width="110" Height="150" Source="{Binding PictureFilename}" VerticalAlignment="Top"/>
<StackPanel Grid.Column="1" VerticalAlignment="Top">
<TextBlock Text="{Binding Name}" Style="{StaticResource PhoneTextLargeStyle}" FontFamily="{StaticResource PhoneFontFamilySemiBold}" Margin="12,-12,12,6"/>
<TextBlock Text="{Binding ShortDescription}" Style="{StaticResource PhoneTextNormalStyle}" TextWrapping="Wrap" FontFamily="{StaticResource PhoneFontFamilySemiBold}"/>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Address:" Style="{StaticResource PhoneTextSmallStyle}"/>
<TextBlock Text="{Binding Path=StreetName}" Style="{StaticResource PhoneTextSmallStyle}" FontFamily="{StaticResource PhoneFontFamilySemiBold}"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Site:" Style="{StaticResource PhoneTextSmallStyle}"/>
<TextBlock Text="{Binding Path=Website}" Style="{StaticResource PhoneTextSmallStyle}" FontFamily="{StaticResource PhoneFontFamilySemiBold}"/>
</StackPanel>
</StackPanel>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Tap">
<cmd:EventToCommand Command="{Binding Path=DataContext.TapCommand, ElementName=searchItems}" CommandParameter="{Binding Path=Id}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Grid>
</DataTemplate>
</toolkit:LongListMultiSelector.ItemTemplate>
</toolkit:LongListMultiSelector>
</Grid>
</StackPanel>
I have this code in XAML, a textbox for search and a multi line select list. The problem is that the multiLineList is not scrollable even if there are many items. If I remove the stackpanel and the textblock and textbox, the list works ok with scroll enabled. Any suggestion?
Try adding a ScrollViewer above your grid.
<ScrollViewer>
<Grid x:Name="LayoutList" ....>
...
</Grid>
</ScrollViewer>
Or you could probably replace your Grid with a ScrollViewer if you're not using it to position your elements.
Wraping LLMS in a ScrollViewer will destroy the item virtualization and throw an OutOfMemoryException if the collection is too long.
Expose the LLMS' inner LongListSelector, then use the ScrollTo() method to scroll to the item u want.
LongListMultiSelector llms = LongListMultiSelector as LongListMultiSelector;
if (llms != null && llms.ItemsSource.Count > 0)
{
llms.InnerLongListSelector.ScrollTo(llms.ItemsSource[llms.ItemsSource.Count - 1]);
}
I've encountered this weird issue and found an easy solution.
It happens for both Longlistselector and LonglistMultiselector.
When you have several controls in one page, you need to set the height of selector's row to "*" instead of "Auto" in order to make the scrolling function to work correctly.
For example :
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/> //Row def for another row
<RowDefinition Height="*"/> //Row def for your selector
</Grid.RowDefinitions>
If the RowDefinition Height not set to "*" but "Auto", scrolling for Longlistselector will not response to user's action.