Create a page indicator in wp8 - xaml

Hi i am trying to implement the slider as shown in the figure below. It is really easy in web using jquery. But the problem is that i have to implement it in wp8. So any idea how do i make circular rings as marked and then on swipe to the right the ring should get marked. Any code snippet if you have any would be great.
thanks

You may try this way. This is just a sample.
MainPage.xaml
<Grid>
<Hub Name="hub" SectionsInViewChanged="Hub_SectionsInViewChanged" >
<HubSection Tag="0" Background="Red" />
<HubSection Tag="1" Background="Blue" />
<HubSection Tag="2" Background="Green" />
<HubSection Tag="3" Background="Aqua" />
</Hub>
<Grid Width="80" Height="30" VerticalAlignment="Bottom" Margin="20,20,20,20">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20" />
<ColumnDefinition Width="20" />
<ColumnDefinition Width="20" />
<ColumnDefinition Width="20" />
</Grid.ColumnDefinitions>
<Ellipse Name="circle1" Margin="5,0,5,0" Fill="White" Width="10" Height="10" Grid.Column="0" Opacity="1"/>
<Ellipse Name="circle2" Margin="5,0,5,0" Fill="White" Width="10" Height="10" Grid.Column="1" Opacity="0.5"/>
<Ellipse Name="circle3" Margin="5,0,5,0" Fill="White" Width="10" Height="10" Grid.Column="2" Opacity="0.5"/>
<Ellipse Name="circle4" Margin="5,0,5,0" Fill="White" Width="10" Height="10" Grid.Column="3" Opacity="0.5"/>
</Grid>
</Grid>
and the function for event SectionsInViewChanged in MainPage.xaml.cs
private void Hub_SectionsInViewChanged(object sender, SectionsInViewChangedEventArgs e)
{
circle1.Opacity = 0.5;
circle2.Opacity = 0.5;
circle3.Opacity = 0.5;
circle4.Opacity = 0.5;
var tag = hub.SectionsInView[0].Tag.ToString();
switch(tag)
{
case "0":
circle1.Opacity = 1;
break;
case "1":
circle2.Opacity = 1;
break;
case "2":
circle3.Opacity = 1;
break;
case "3":
circle4.Opacity = 1;
break;
default :
circle1.Opacity = 1;
break;
}
}

Related

Windows Phone UWP : App getting crash while swipe, Pivot Control Without any exception

I am using pivot control for swiping some number of articles(e.g:20) based on following XAML design
<Page
x:Class="NAMESPACE.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:NAMESPACE"
xmlns:ViewModels="using:NAMESPACE.ViewModels"
xmlns:common="using:NAMESPACE.Classes"
xmlns:stringBind="using:NAMESPACE.Classes"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:q42controls="using:Q42.WinRT.Controls"
xmlns:UI="using:Microsoft.Advertising.WinRT.UI"
Background="Gray"
mc:Ignorable="d">
<Page.Resources>
<ViewModels:ArticleViewModel x:Key="ViewModel" />
<DataTemplate x:Key="headerTest">
</DataTemplate>
<DataTemplate x:Key="pivotTemplate">
<StackPanel Margin="-15 0 -15 0">
<Grid>
<Image x:Name="PlaceHolderImage" Source="Assets/PlaceHolder.jpg"></Image>
<Image q42controls:ImageExtensions.CacheUri="{Binding ImageURL}" Tag="{Binding ImageURL}" Tapped="ImageView"></Image>
</Grid>
<StackPanel Background="Black">
<TextBlock Text="{Binding UpdatedDate}" FontSize="15" HorizontalAlignment="Center"
VerticalAlignment="Center" Pivot.SlideInAnimationGroup="GroupTwo" Margin="10 10 0 10"
FontFamily="{StaticResource ContentControlThemeFontFamily}"
Foreground="#777"></TextBlock>
<Border VerticalAlignment="Bottom" Height="1" Background="Black" Opacity="0.1">
</Border>
<RichTextBlock x:Name="HeadLine" local:Properties.Html="{Binding HeadLine}"
Margin="10 5 10 -5" TextWrapping="Wrap"
FontSize="{Binding HeadlineFontSize}" Foreground="White"
FontFamily="{StaticResource HeadlineCommonFamiy}"
Pivot.SlideInAnimationGroup="GroupTwo"
IsTextSelectionEnabled="True"/>
<RichTextBlock local:Properties.Html="{Binding Abstract}" TextWrapping="Wrap" FontSize="{Binding AbstractFontSize}"
Pivot.SlideInAnimationGroup="GroupTwo" Margin="10 5 10 10"
Foreground="#999"
FontFamily="{StaticResource AbstractCommonFamily}"
IsTextSelectionEnabled="True"/>
</StackPanel>
<StackPanel x:Name="descriptionSP" Background="Black">
<Image Source="Assets/PlaceHolder.jpg" Width="300" Height="250"></Image>
<UI:AdControl
AutoRefreshIntervalInSeconds="60"
ApplicationId="3f83fe91-d6be-434d-a0ae-7351c5a997f1"
AdUnitId="10865270"
HorizontalAlignment="Center"
Height="250"
IsAutoRefreshEnabled="True"
VerticalAlignment="Top"
Margin="5,-240,5,5"
Width="300"/>
<RichTextBlock IsTextSelectionEnabled="True" x:Name="richTextBlock"
local:Properties.Html="{Binding ArticleDetail}" TextWrapping="Wrap"
FontSize="{Binding FontSize}" Foreground="White"
Pivot.SlideInAnimationGroup="GroupTwo" Margin="10,10,10,-20"
FontFamily="{StaticResource ContentControlThemeFontFamily}">
</RichTextBlock>
<Image Source="Assets/PlaceHolder.jpg" Width="300" Height="250"></Image>
<UI:AdControl
AutoRefreshIntervalInSeconds="60"
ApplicationId="3f83fe91-d6be-434d-a0ae-7351c5a997f1"
AdUnitId="10865270"
HorizontalAlignment="Center"
Height="250"
IsAutoRefreshEnabled="True"
VerticalAlignment="Top"
Margin="5,-220,5,5"
Width="300"/>
<WebView x:Name="criticWebView" Visibility="{Binding WebViewVisibility}" Height="300"
Source="{Binding CriticReviewUrl}" />
</StackPanel>
</StackPanel>
</DataTemplate>
</Page.Resources>
<Page.BottomAppBar>
<CommandBar Foreground="White" Background="Black">
<CommandBar.PrimaryCommands>
<AppBarButton x:Uid="Share" Foreground="White" Click="Share_Click" Label="Share">
<AppBarButton.Icon>
<BitmapIcon Foreground="White" UriSource="/Assets/Share.png" Height="30" Margin="0,-5,0,0"/>
</AppBarButton.Icon>
</AppBarButton>
<AppBarButton Icon="Favorite" Foreground="White" Name="favIcon" Click="Favorite_Click" Label="Favorite" Margin="0,-2,0,0"></AppBarButton>
<AppBarButton Icon="Setting" Foreground="White" Name="Settings" Click="Settings_Click" Label="Settings" Margin="0,-2,0,0"></AppBarButton>
</CommandBar.PrimaryCommands>
</CommandBar>
</Page.BottomAppBar>
<Grid Background="Black" x:Name="grid">
<Grid x:Name="LoadingGrid" Visibility="Visible">
<ProgressRing x:Name="progressRing" IsActive="True" Foreground="#d03438" HorizontalAlignment="Center" Width="60"
Height="50" VerticalAlignment="Center" Margin="0 20 0 0"></ProgressRing>
</Grid>
<Grid x:Name="mainGrid">
<Grid.RowDefinitions>
<RowDefinition Height="40"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Image x:Name="logoImage" Grid.Row="0" Source="Assets/Maalaimalar_logo.png" HorizontalAlignment="Center" Margin="1 5 0 0"></Image>
<ScrollViewer x:Name="swipeBetweenPages" Grid.Row="1" Visibility="Collapsed">
<Pivot DataContext="{StaticResource ViewModel}" x:Name="pivot" Margin="0,-45,0,0"
HeaderTemplate="{StaticResource headerTest}"
ItemTemplate="{StaticResource pivotTemplate}" ItemsSource="{Binding Articles}" SelectionChanged="pivot_SelectionChanged">
</Pivot>
</ScrollViewer>
</Grid>
<Grid Visibility="Collapsed" VerticalAlignment="Center" HorizontalAlignment="Center" Background="Black" Name="popUp">
<Grid.RowDefinitions>
<RowDefinition Height="40"></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Image Source="/Assets/Close_White.png" HorizontalAlignment="Right" Grid.Row="1" Tapped="CloseImage"
VerticalAlignment="Top" Margin="0,30,0,0" Height="30"></Image>
<ScrollViewer x:Name="scroll" ZoomMode="Enabled" Grid.Row="2">
<Image x:Name="popUpImage" VerticalAlignment="Center" Margin="0,-50,0,0"></Image>
</ScrollViewer>
</Grid>
</Grid>
</Page>
And below is the code behind to bind the data in to XAML
data = e.Parameter as Feed;
feedList = data.Articles;
localSettings.Values["ChildName"] = feedList[0].ChildName;
for (int z = 0; z < feedList.Count; z++)
{
string articleDetail = WebUtility.HtmlDecode(feedList[z].ArticleDetail);
articleDetail = articleDetail.Replace("<[^>]*>", Environment.NewLine);
articleDetail = articleDetail.Replace("<div><br /></div>", "<br /><br />");
feedList[z].ArticleDetail = articleDetail;
if (feedList[z].ChildName == "Review")
{
feedList[z].WebViewVisibility = "Visible";
feedList[z].CriticReviewUrl = feedList[z].CriticReviewUrl.Replace("Review", "CriticReviewMobile");
feedList[z].CriticReviewUrl = Constants.Constants.BaseUrl.CriticUrl + feedList[z].CriticReviewUrl;
}
else
feedList[z].WebViewVisibility = "Collapsed";
}
index = data.ListingIndex + 1;
if (index > feedList.Count - 1)
{
index = 0;
}
if (index == 0)
{
index = feedList.Count;
}
List<Article> feedList1 = new List<Article>();
feedList1.Add(feedList[index - 1]);
int j = index;
for (int i = 0; i < feedList.Count - 1; i++)
{
if (j >= feedList.Count)
{
j = 0;
}
feedList1.Add(feedList[j]);
j++;
}
feedList = feedList1;
var viewModel = pivot.DataContext as ArticleViewModel;
viewModel.BindListToView(feedList);
LoadingGrid.Visibility = Visibility.Collapsed;
swipeBetweenPages.Visibility = Visibility.Visible;
While Swipe, the app gets crash after 5 or less swipe with out any exception. I have included hockey app into my app, but the crash is not handled in the crash report also.
Please help me to resolve the issue..

UWP Grid RowSpan with ScroolViewer

If you paste this code in the mainpage of a new UWP app (or look at the 1st picture) you can see that the orange grid is taking more space than needed (VerticalAlignment is set to top). To make it work like it should, you have to set the 2nd row's height of this grid to Auto (see 2nd picture). The problem is that I want to give the extra space to the 2nd/last row and not to distribute it across all rows.
Putting the controls in the left column inside their own grid works (obviously, because there is no rowspan) but I can't do that because when the screen narrows the stackpanel in the right column goes inside a row in the left column.
The second problem is that if you click on the orange/green/yellow space, focus goes always to the textbox in the first row (yellow).
UPDATE: both problems are fixed without the scrollviewer but I clearly need it.
<Page
x:Class="App1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<ScrollViewer Background="DarkGreen" VerticalScrollBarVisibility="Auto">
<Grid Background="DarkOrange" Margin="10" VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Background="Yellow">
<TextBlock Text="Title" />
<TextBox Margin="20" />
</StackPanel>
<Grid Grid.Row="1" Background="DeepPink" VerticalAlignment="Top">
<ListView Margin="10" VerticalAlignment="Top">
<ListView.Items>
<TextBlock Text="Item1" />
</ListView.Items>
</ListView>
</Grid>
<StackPanel Grid.Column="1" Grid.RowSpan="2" Background="Blue" VerticalAlignment="Top">
<StackPanel>
<TextBlock Text="Title1" />
<GridView Margin="0,10,0,0">
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsWrapGrid Orientation="Horizontal" MaximumRowsOrColumns="4" />
</ItemsPanelTemplate>
</GridView.ItemsPanel>
<GridView.Items>
<Rectangle Width="80" Height="80" Fill="White" />
<Rectangle Width="80" Height="80" Fill="White" />
<Rectangle Width="80" Height="80" Fill="White" />
<Rectangle Width="80" Height="80" Fill="White" />
<Rectangle Width="80" Height="80" Fill="White" />
<Rectangle Width="80" Height="80" Fill="White" />
<Rectangle Width="80" Height="80" Fill="White" />
<Rectangle Width="80" Height="80" Fill="White" />
<Rectangle Width="80" Height="80" Fill="White" />
<Rectangle Width="80" Height="80" Fill="White" />
<Rectangle Width="80" Height="80" Fill="White" />
<Rectangle Width="80" Height="80" Fill="White" />
</GridView.Items>
</GridView>
</StackPanel>
<StackPanel>
<TextBlock Text="Title2" />
<GridView Margin="0,10,0,0">
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsWrapGrid Orientation="Horizontal" MaximumRowsOrColumns="4" />
</ItemsPanelTemplate>
</GridView.ItemsPanel>
<GridView.Items>
<Rectangle Width="80" Height="80" Fill="White" />
<Rectangle Width="80" Height="80" Fill="White" />
<Rectangle Width="80" Height="80" Fill="White" />
<Rectangle Width="80" Height="80" Fill="White" />
<Rectangle Width="80" Height="80" Fill="White" />
<Rectangle Width="80" Height="80" Fill="White" />
<Rectangle Width="80" Height="80" Fill="White" />
<Rectangle Width="80" Height="80" Fill="White" />
<Rectangle Width="80" Height="80" Fill="White" />
<Rectangle Width="80" Height="80" Fill="White" />
<Rectangle Width="80" Height="80" Fill="White" />
<Rectangle Width="80" Height="80" Fill="White" />
</GridView.Items>
</GridView>
</StackPanel>
</StackPanel>
</Grid>
</ScrollViewer>
</Grid>
I found a workaround. Since the first row is not going to expand or change, I set the first row's MaxHeight property equal to the actual height of the row at runtime.
For the second problem set the IsTabStop property of the scrollviewer to True as explained here:
https://social.msdn.microsoft.com/Forums/windowsapps/en-US/32e026dd-8338-4c19-a7d6-1bb8797044b3/first-input-control-in-the-scroll-viewer-is-always-getting-focused?prof=required

Caption of a grid in a windows universal project

I am trying to set a caption (something like the caption of a html table control) for my grid control but I am not seeing any property related to that. Am I missing something ?
Currently I am thinking to set the grid caption using another TextBlock control having the same alignment with the grid... but this seems to get complicated for such a simple thing.
Do you know, is there another way to set the caption of a grid in a universal windows project ?
Add another row to your grid. Then add a TextBlock to the last row for the caption. Set the Grid ColumnSpan property, for the TextBlock, to span all of the columns in your grid.
Here is an example:
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" HorizontalAlignment="Center" VerticalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="50" />
<RowDefinition Height="50" />
<RowDefinition Height="50" />
<RowDefinition Height="25" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50" />
<ColumnDefinition Width="50" />
<ColumnDefinition Width="50" />
<ColumnDefinition Width="50" />
</Grid.ColumnDefinitions>
<Rectangle Grid.Row="0" Grid.Column="0" Fill="White" />
<Rectangle Grid.Row="0" Grid.Column="1" Fill="Black" />
<Rectangle Grid.Row="0" Grid.Column="2" Fill="White" />
<Rectangle Grid.Row="0" Grid.Column="3" Fill="Black" />
<Rectangle Grid.Row="1" Grid.Column="0" Fill="Black" />
<Rectangle Grid.Row="1" Grid.Column="1" Fill="White" />
<Rectangle Grid.Row="1" Grid.Column="2" Fill="Black" />
<Rectangle Grid.Row="1" Grid.Column="3" Fill="White" />
<Rectangle Grid.Row="2" Grid.Column="0" Fill="White" />
<Rectangle Grid.Row="2" Grid.Column="1" Fill="Black" />
<Rectangle Grid.Row="2" Grid.Column="2" Fill="White" />
<Rectangle Grid.Row="2" Grid.Column="3" Fill="Black" />
<Rectangle Grid.Row="3" Grid.Column="0" Fill="Black" />
<Rectangle Grid.Row="3" Grid.Column="1" Fill="White" />
<Rectangle Grid.Row="3" Grid.Column="2" Fill="Black" />
<Rectangle Grid.Row="3" Grid.Column="3" Fill="White" />
<TextBlock Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="4"
Text="This is a Caption"
HorizontalAlignment="Center" VerticalAlignment="Center"
Foreground="Black" FontSize="10"/>
</Grid>
Currently I am thinking to set the grid caption using another TextBlock control having the same alignment with the grid... but this seems to get complicated for such a simple thing.
This is an acceptable solution, Mike Jablonski has provided a sample. If you need to ensure reusability, you can create a UserControl which using TextBlock control to show Caption, registering a dependency property is a good way to set "Caption" for this UserControl, see Dependency properties overview

Inner Items in UWP Grid not stretching

I am Having an issue with my items in this Grid not spanning the width of the screen. Sorry if my code is sloppy. A bit new at this.
Thanks in advance!
Not the full code - wasn't sure if you would need it.
<Grid x:Name="grid" Margin="0,0,0,54" VerticalAlignment="Bottom" Height="39" Style="{Binding HorizontalAlignment, ElementName=grid}" ScrollViewer.HorizontalScrollBarVisibility="Auto" >
<StackPanel Orientation="Horizontal" >
<Button Margin="0,12,0,-2" Height="32" Width="Auto" HorizontalContentAlignment="Stretch">
<Button.Content>
<Image Source="images/icon1.png" Margin="-9.667,-3,-9.667,-1"/>
</Button.Content>
</Button>
<Button Margin="0,12,0,-2" Height="32" Width="Auto" HorizontalContentAlignment="Stretch" >
<Button.Content>
<Image Source="images/icon2.png" Margin="-10,-3,-10,-1"/>
</Button.Content>
</Button>
<Border Background="#d1d3d4" x:Name="typeHeader11" Grid.Column="1" Margin="0,24,0,9" RenderTransformOrigin="0.5,0.5" Width="17" HorizontalAlignment="Stretch">
<Border.RenderTransform>
<CompositeTransform ScaleX="-1"/>
</Border.RenderTransform>
<Image Source="images/like.png"></Image>
</Border>
<Border Background="#d1d3d4" x:Name="typeHeader" Grid.Column="2" Margin="0,24,0,9" Width="67" HorizontalAlignment="Stretch">
<TextBlock Text="221" Width="20" Margin="0,7,0,10" FontSize="10.667" />
</Border>
<Border x:Name="typeHeader12" Grid.Column="1" Margin="0,24,0,9" RenderTransformOrigin="0.5,0.5" Width="17" HorizontalAlignment="Stretch">
<Border.RenderTransform>
<CompositeTransform ScaleX="-1"/>
</Border.RenderTransform>
<Image Source="images/dislike.png"></Image>
</Border>
<Border x:Name="typeHeader2" Grid.Column="2" Margin="0,24,0,9" Width="56" HorizontalAlignment="Stretch">
<TextBlock Text="221" Width="20" Margin="0,7,0,10" Foreground="#FFFDF3F3" FontSize="10.667" />
</Border>
<Border x:Name="typeHeader13" Grid.Column="1" Margin="0,24,0,9" RenderTransformOrigin="0.5,0.5" Width="17" HorizontalAlignment="Stretch">
<Border.RenderTransform>
<CompositeTransform ScaleX="-1"/>
</Border.RenderTransform>
<Image Source="images/comment.png"></Image>
</Border>
<Border Background="#d1d3d4" x:Name="typeHeader3" Grid.Column="2" Margin="0,24,0,9" Width="57" HorizontalAlignment="Stretch">
<TextBlock Text="221" Width="20" Margin="0,7,0,10" FontSize="10.667" />
</Border>
</StackPanel>
</Grid>
StackPanel does not stretch, use Grid and columns if you want to span items to the width of screen
<Grid x:Name="grid" ...>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/> // Auto adjust space
<ColumnDefinition Width="Auto"/> // Auto adjust space
<ColumnDefinition Width="*"/> // * = Stretch to fill
<ColumnDefinition Width="Auto"/> // Auto adjust space
</Grid.ColumnDefinitions>
<Button Grid.Column="0" ... />
<Button Grid.Column="1" ... />
<Button Grid.Column="2" ... /> // This will now expand as you resize window
<Button Grid.Column="3" ... />
</Grid>

Image filling a button UWP Xaml

I am having problem in stretching my image to fill the button,I am new in UWP this is my code:
<Grid Margin="0,0,0,54" VerticalAlignment="Bottom" Height="39" Style="{Binding HorizontalAlignment, ElementName=grid}" ScrollViewer.HorizontalScrollBarVisibility="Auto">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button Grid.Column="0" Height="39" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
<Image Source="images/icon1.png" Stretch="Fill" RenderTransformOrigin="0.5,0.5" UseLayoutRounding="True" d:LayoutRounding="Auto" />
</Button>
<Button Grid.Column="1" Height="39" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
<Image Source="images/icon2.png" Stretch="Fill" RenderTransformOrigin="0.5,0.5" UseLayoutRounding="True" d:LayoutRounding="Auto" />
</Button>
</Grid>
You probably need to change the Padding and BorderThickness properties of the button. As code below :
<Button Grid.Column="0" Height="39" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Padding="0" BorderThickness="0">
<Image Source="Assets/microsoft.png" Stretch="UniformToFill"/>
</Button>