How to "Center" listview items in a column - html

Seem no matter where I put the HorizentalAlignment = "Center" in my ListViewColumn it doesn't effect the outcome.
This is all I have tried so far,
<ListView.View>
<GridView>
<GridViewColumn Header="Device name" Width="120" DisplayMemberBinding="{Binding Path=DeviceName}"/>
<GridViewColumn>
<GridViewColumnHeader Content=" GPS Signal " />
<GridViewColumn.CellTemplate>
<DataTemplate>
<Grid HorizontalAlignment="Center">
<Image Width="13" HorizontalAlignment="Center" Source="{Binding Path=GpsSignalImagePath}"/>
</Grid>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn>
</GridView>
</ListView.View>
</ListView>
As you can see it's mentioned in Grid and also in Image itself but no luck. The result shows up aligned to left as it's shown in the picture below.

Set the HorizontalAlignment inside ItemsPanelTemplate like this
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<Grid HorizontalAlignment="Center"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>

You can try to set HorizontalContentAlignment of ListViewItem from style to alter alingment of cell's content :
<ListView ....>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Center" />
</Style>
</ListView.ItemContainerStyle>
......
......
</ListView>

Related

WebView in FlipViewItem - WebView does not accept any gestures

I've put a WebView inside of a FlipViewItem. The problem seems to be that in WP 8.1, the WebView does not get the gestures (presumably because they're absorbed by the FlipView). The desired result is to be able to scroll vertically and tap in the WebView but also to be able scroll horizontally for the FlipView (even if just in a limited area on the horizontal edges). Is there any solution or workaround for this?
<StackPanel>
<StackPanel Name="postTitle" Background="Transparent">
<TextBlock Name="ContentArea" Text="" FontSize="18" Margin="10, 5, 10, 0" TextWrapping="WrapWholeWords" FontWeight="Bold" Foreground="White"/>
<TextBlock Name="SubArea" Text="" FontSize="16" Margin="10, 0, 10, 10" TextWrapping="WrapWholeWords" Foreground="White"/>
</StackPanel>
<FlipView Name="swipeArea" Height="460" Margin="0" Padding="0" SelectedIndex="1" SelectionChanged="swipeArea_SelectionChanged">
<FlipViewItem Name="oneItem">
</FlipViewItem>
<FlipViewItem Name="mainFlipViewItem">
<Grid>
<ProgressRing Name="progRing" Foreground="White" Margin="0,25,0,0" Background="Transparent" Visibility="Collapsed" VerticalAlignment="Top"/>
<WebView Name="InterWindow" Height="460" Visibility="Collapsed" DefaultBackgroundColor="#5E5E5E"></WebView>
<ScrollViewer Name="Scrollster" ZoomMode="Enabled" MinZoomFactor="1" MaxZoomFactor="8" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<Image Name="WebWindow" Height="420" HorizontalAlignment="Center" VerticalAlignment="Top">
</Image>
</ScrollViewer>
</Grid>
</FlipViewItem>
<FlipViewItem Name="threeItem">
</FlipViewItem>
</FlipView>
</StackPanel>
I believe I just found one workaround. I've added this to the WebView control:
Canvas.ZIndex="1000"
I can then set the width of the WebView control to something just slimmer than the FlipView itself, and then I should be good.

Adding image to title of Pivot page and handling touch

I am trying to add image next to pivot control title and I want to be able to touch it. But I can't and I guess it's because pivot is handling touches. This is my code:
<Grid Margin="162,22,0,0" VerticalAlignment="Top" HorizontalAlignment="Left"
Tap="MessagesIcon_OnTap">
<Image Source="/Assets/Images/Icons/messages_icon.png"
x:Name="MessagesIcon"
Stretch="Fill" Opacity="1" Width="20" Height="22"
Tap="MessagesIcon_OnTap"/>
</Grid>
<phone:Pivot x:Name="PlayerPivot" Title="TITLE" >
<!--Pivot item one-->
<phone:PivotItem Margin="0" x:Name="PlayingPivotItem">
<phone:PivotItem.Header>
<TextBlock Text="subtitle" />
</phone:PivotItem.Header>
<Grid x:Name="ContentPanel">
...
As you can see I tried catch tap on both (grid which contains image and image it self) but it isn't call. What is the easiest way to get tap gesture on image? Thanks
Give a try using this snippet:
<controls:Pivot.Title>
<StackPanel>
<TextBlock Text="title" />
<Image Source="/Images/anyimage.png"/>
</StackPanel>
</controls:Pivot.Title>

How to create dynmaic pivot items for ItemsControl in windows phone?

create Pivot control with dynamic pivot items, within the pivot datatemplate have to show Items control that too will have data template..like below
<phone:Pivot x:Name="chatPivot" Margin="0 2 0 76" ItemsSource="{Binding Contacts}" SelectionChanged="chatPivot_SelectionChanged"> <phone:Pivot.ItemTemplate>
<DataTemplate>
<ScrollViewer x:Name="chatScroll" Margin="0,0,0,72" VerticalScrollBarVisibility="Auto">
<ItemsControl Margin="0" x:Name="chats" Tap="chats_Tap_1" ItemsSource="{Binding Messages}"
ItemTemplate="{StaticResource imgItemTemplate}" ItemsPanel="{StaticResource imgItemPanel}">
</ItemsControl>
</ScrollViewer>
</DataTemplate>
</phone:Pivot.ItemTemplate>
</phone:Pivot>
Here is my dataTemplate.
<phone:PhoneApplicationPage.Resources>
<ItemsPanelTemplate x:Key="imgItemPanel">
<StackPanel Orientation="Vertical" />
</ItemsPanelTemplate>
<DataTemplate x:Key="imgItemTemplate" >
<chatbubble:ChatBubbleControl x:Name="ChatBubble" Hold="ChatBubbleControl_Hold_1" />
</DataTemplate>
</phone:PhoneApplicationPage.Resources>
I actually do not know the design of your "ChatbubbleControl" usercontrol but I found one issue why values are not getting bound.
<phone:PhoneApplicationPage.Resources>
<ItemsPanelTemplate x:Key="imgItemPanel">
<StackPanel Orientation="Vertical" />
</ItemsPanelTemplate>
<DataTemplate x:Key="imgItemTemplate" >
<chatbubble:ChatBubbleControl x:Name="ChatBubble" xyz="{Binding}" Hold="ChatBubbleControl_Hold_1" />
</DataTemplate>
</phone:PhoneApplicationPage.Resources>
You are binding value to ItemsControl but you are not binding any value to actual control (here, chatbubblecontrol) that is displaying the value on screen.
The solution is the you need to create a property to your usercontrol e.g.: Here, I made a test property named "xyz". and then try to bind the values to it.
Hope this will help you conceptually.

Windows Store ListView ItemStackPanel horizontal scrollbar not visible

Im having Listview which shows 185 columns and 15 rows. For showing 185 columns with 15 rows, windows store app takes some time or UI gets freezes. below is the code Im using for showing data
<ListView x:Name="outerlstView"
Height="650"
Margin="2,24,10,10" Grid.Row="1"
Grid.Column="1" BorderThickness="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
ItemsSource="{Binding Data,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
ScrollViewer.HorizontalScrollBarVisibility="Visible"
ScrollViewer.HorizontalScrollMode="Enabled" ScrollViewer.VerticalScrollBarVisibility="Auto"
SelectionMode="None" ShowsScrollingPlaceholders="True" IsZoomedInView="False"
IsSwipeEnabled="False" IsItemClickEnabled="False"
ItemContainerStyle="{StaticResource LvItemStyle}"
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel
Orientation="Vertical" VirtualizingStackPanel.VirtualizationMode="Standard"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<ListView SelectionMode="None" IsZoomedInView="False" IsHoldingEnabled="False"
IsSwipeEnabled="False" x:Name="ListRow" ItemsSource="{Binding data, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Stretch" Width="Auto" Height="Auto"
VerticalAlignment="Center" ItemContainerStyle="{StaticResource LvItemStyle}" AllowDrop="True"
ShowsScrollingPlaceholders="True">
<interactivity:Interaction.Behaviors>
<awbehaviors:DragBehaviour/>
</interactivity:Interaction.Behaviors>
<ListView.ItemTemplate>
<DataTemplate>
<Grid Height="35" Width="120" HorizontalAlignment="Center" >
<Rectangle StrokeDashArray="1 1 0.3 1" Height="30" VerticalAlignment="Top" IsHitTestVisible="False" Opacity="0.5" Stroke="White" StrokeThickness="1" Margin="0" StrokeEndLineCap="Square" StrokeDashOffset="1.5"
Fill="{Binding ElementName=ListRow,Path=Tag,Converter={StaticResource RowNotoBackgroundConverter}}"/>
<TextBlock Text="{Binding FeedCellData,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Left"
tyle="{StaticResource GridItemTextStyle}" Width="120" AllowDrop="True" Padding="1" TextWrapping="NoWrap"
VerticalAlignment="Top" Tag="{Binding ElementName=ListRow,Path=Tag}" ToolTipService.ToolTip="{Binding FeedCellData}"
Height="{Binding Path=Tag, RelativeSource={RelativeSource Mode=Self},Converter={StaticResource RowtoHeightConverter }}" >
</TextBlock>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsStackPanel Margin="0,0,0,0" Width="Auto" Orientation="Horizontal" Height="35" VirtualizingStackPanel.VirtualizationMode="Standard"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
the above code has listview inside it another listview. when i try to load list<list> to listview it takes too much of time. Some time app crashes when i load 100 rows with 185 columns.
I tried to replace Itemtemplate stye control to Itemstackpanel performance is good. data is loaded and shown on screen faster but i dont see Horizontal scroll
Previous Code
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel
Orientation="Vertical" VirtualizingStackPanel.VirtualizationMode="Standard"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
when i modify to `<ListView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsStackPanel Margin="0,0,0,0" Width="Auto" Orientation="Horizontal" Height="35" VirtualizingStackPanel.VirtualizationMode="Standard"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>`
i dont see horizontal scrollbar enabled. Can any1 suggest me how to enable Horizontal scroll bar enabled by default to Itemstackpanel in windows store apps.Looks like it is bug with this control or there work arounds to ItemsStackpanel with Horizontal Scrollbar.
If your ItensSource is a list of objects with a attribute Name and a attribute Price for example:
<ListView ItemsSource="{Binding Here_your_DataSource}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.VerticalScrollBarVisibility="Visible" >
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<WrapGrid Orientation="Horizontal" MaximumRowsOrColumns="15"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<!--Here u design your item template-->
<StackPanel Background="Blue" Width="100" Height="100">
<TextBlock Text="{Binding Name}"></TextBlock>
<TextBlock Text="{Binding Price}"></TextBlock>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>

WP8 Progress Bar Not Rendering

I have placed a Progress Bar control within my MainPage.xaml. The application type is Pivot.
For some reason, the Progress Bar and a TextBlock which I have placed within a PivotItem and below a Grid are not showing. There is a LongListSelector directly beneath these two controls. Are these two controls not showing because of that? I used the UI to drag the LongListSelector beneath then anyway, so I'm not sure why it's not showing.
This is the XAML:
<phone:Pivot Title="Title" Background="White" Foreground="Black">
<!--Pivot item one-->
<phone:PivotItem Header="Header" Foreground="Black">
<Grid>
<ProgressBar Name="progressBar" Value="0" IsIndeterminate="True" Margin="0,0,0,579"/>
<TextBlock Name="txtLastUpdated" FontWeight="Black" FontStyle="Italic" Foreground="Black" Margin="0,24,0,541" />
<phone:LongListSelector Name="llsLocations" ItemsSource="{Binding}" SelectionChanged="LongListSelector_OnSelectionChanged" Margin="0,62,0,0">
<phone:LongListSelector.ItemTemplate>
...
...
...
As you can see, there is a ProgressBar and a TextBlock above the LongListSelector who are also inside the Grid control.
Any ideas why these two controls are not showing?
I think you have something wrong with Margin or item positioning. I've tested code below and it works:
<phone:Pivot Title="Title" Background="White" Foreground="Black">
<!--Pivot item one-->
<phone:PivotItem Header="Header" Foreground="Black">
<Grid>
<StackPanel Orientation="Vertical" VerticalAlignment="Center">
<ProgressBar Name="progressBar" Value="0" IsIndeterminate="True" VerticalAlignment="Center" Margin="0"/>
<TextBlock Name="txtLastUpdated" FontWeight="Black" FontStyle="Italic" Foreground="Black"
HorizontalAlignment="Center" Text="Something"/>
</StackPanel>
<phone:LongListSelector Name="llsLocations" ItemsSource="{Binding}" SelectionChanged="LongListSelector_OnSelectionChanged" Margin="0,62,0,0"/>
</Grid>
</phone:PivotItem>
</phone:Pivot>
Remove margin of all child element of StackPanel. This will defiantly helps you.
<phone:Pivot Title="Title" Background="White" Foreground="Black">
<!--Pivot item one-->
<phone:PivotItem Header="Header" Foreground="Black">
<Grid>
<StackPanel>
<ProgressBar Name="progressBar" Value="0" IsIndeterminate="True"/>
<TextBlock Name="txtLastUpdated" FontWeight="Black" FontStyle="Italic" Foreground="Black" />
<phone:LongListSelector Name="llsLocations" ItemsSource="{Binding}" SelectionChanged="LongListSelector_OnSelectionChanged" >
<phone:LongListSelector.ItemTemplate>
</StackPanel>
</Grid>
</phone:PivotItem>
</<phone:Pivot>
Hardcoding control's position (especially by dragging controls in designer) is not a good practice. Try to define rows for your Grid, then specify Grid.Row for controls inside the Grid. With that you can arrange Grid content more neatly. Check this link for more sample and explanation about layouting controls inside Grid. Following is an example for your situation :
<phone:PivotItem Header="Header" Foreground="Black">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0">
<ProgressBar Name="progressBar" Value="0" IsIndeterminate="True" />
<TextBlock Name="txtLastUpdated" FontWeight="Black" FontStyle="Italic" Foreground="Black" />
</StackPanel>
<phone:LongListSelector Grid.Row="1" Name="llsLocations" ItemsSource="{Binding}" SelectionChanged="LongListSelector_OnSelectionChanged" >
<phone:LongListSelector.ItemTemplate>
...
...