How to obtain full width in PivotItem - xaml

In XAML, PivotItems don't have full width of the screen on a Windows Phone. This is good behavior and design, but for a single image I want it to fill the entire screenwidth.
Can this be accomplished?

The root cause is that default PivotItemMargin is set to 12,0,12,0. We can find the setting in generic.xaml.
So what we need to do is overridding the setting in App.xaml. Just like this:
<Thickness x:Key="PivotItemMargin">0</Thickness>

This is the solution, having a negative margin
<controls:Pivot>
<controls:PivotItem Margin="-10,0,-10,0">
<Grid />
</controls:PivotItem>
<controls:PivotItem Margin="-10,0,-10,0">
<Grid />
</controls:PivotItem>
</controls:Pivot>
Of course you can also use a regular pivot and only have the image margin set to -10,0,-10,0

Please Use this code,
<phone:PhoneApplicationPage
x:Class="NikhilSApp.DemoExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="800"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="False">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<!--Pivot Control-->
// You can specify the width here....
<controls:Pivot Height="800" Width="480">
<!--Pivot item one-->
<controls:PivotItem Height="800" Margin="0,-130,0,0">
<Grid Name="GridMediaQuestion">
<Image HorizontalAlignment="Center" Source="Images/Guess.png" Margin="10,10,10,10" Name="imgReceived" Stretch="Fill" VerticalAlignment="Center" Height="790" Width="470" />
</Grid>
</controls:PivotItem>
<!--Pivot item two-->
<controls:PivotItem Height="800" >
<Grid x:Name="GridPivot2" Background="#ffffc0">
// Place Your Second pivot's Content here
</Grid>
</controls:PivotItem>
</controls:Pivot>
</Grid>
It is Working..
I implemented already... :)

Related

Binding height and width of border to half of its children at runtime in windows 8.1 app

I have a user control which have elements like this
<UserControl
x:Class="App2.MyImageControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App2"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
<Grid x:Name="MyGrid" x:FieldModifier="public" ManipulationMode="None" Tapped="MyGrid_Tapped" HorizontalAlignment="Left" VerticalAlignment="Top" >
<Grid.RenderTransform>
<CompositeTransform></CompositeTransform>
</Grid.RenderTransform>
<Border x:Name="MyBorder" x:FieldModifier="public" BorderThickness="1" BorderBrush="Transparent" Width="auto" Height="auto">
<Grid>
<Image x:Name="MyImageO" x:FieldModifier="public" Source="" Width="auto" Height="auto" Stretch="Fill"></Image>
</Grid>
</Border>
</Grid>
I want to bind MyBorder width and height to half of MyImageO width and height at runtime.How do I achieve that .
You could try using the MultiplyConverter to convert a bound value to half of it, but ActualWidth and ActualHeight aren't bindable - they don't raise change notifications. Your best bet is to simply handle SizeChanged events and then set the dimensions of the border based on ActualWidth and ActualHeight of the image.

Windows phone style updation not working

I have applied style to textblocks in my windows phone 7.1 app, and this is reflected in VS designer. But when I run it, changes are not visible at all. Code runs without error, except that changes are lost while debugging it, and Background property isn't showing any changes in designer and debugging mode.
<Application
x:Class="PhoneApp1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone">
<!--Application Resources-->
<Application.Resources>
<Color x:Key="Foreground">Red</Color>
<SolidColorBrush
x:Key="PhoneForegroundBrush"
Color="{StaticResource Foreground}"/>
<Style TargetType="TextBlock" x:Key="PhoneTextNormalStyle">
<Setter Property="FontSize" Value="55"/>
</Style>
</Application.Resources>
<Application.ApplicationLifetimeObjects>
<!--Required object that handles lifetime events for the application-->
<shell:PhoneApplicationService
Launching="Application_Launching" Closing="Application_Closing"
Activated="Application_Activated" Deactivated="Application_Deactivated"/>
</Application.ApplicationLifetimeObjects>
</Application>
<phone:PhoneApplicationPage
x:Class="PhoneApp1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
Background="{StaticResource PhoneBackgroundBrush}"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="Guess markets" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="Nifty" Margin="9,-7,0,0" Style="{StaticResource PhoneTextNormalStyle}" />
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<TextBlock Text="Level"/>
</Grid>
</Grid>
<!--Sample code showing usage of ApplicationBar-->
<!--<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
<shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Button 1"/>
<shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="Button 2"/>
<shell:ApplicationBar.MenuItems>
<shell:ApplicationBarMenuItem Text="MenuItem 1"/>
<shell:ApplicationBarMenuItem Text="MenuItem 2"/>
</shell:ApplicationBar.MenuItems>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>-->
</phone:PhoneApplicationPage>
Try this code within your Application.Resources tag
<Application.Resources>
<Style TargetType="TextBlock" x:Key="PhoneTextNormalStyle">
<Setter Property="FontSize" Value="55"/>
<Setter Property="ForeGround" Value="Black"/>
</Style>
</Application.Resources>
Give a foreground color to the text and see.
There's nothing wrong with which you've posted.
Hope it helps!

XamlParseException: Cannot find a Resource with the Name/Key PhoneBackgroundBrush [Line: 47 Position: 111]

When I first started developing everything was fine but then started up the project for the second time got this error. Since there is an error in the xaml the preview of the design layout never shows so I'm working blindly here.
Did some research, where this individual had the exact problem as me but I tried their solution but it didn't work for me maybe because they were working with Windows Phone 7.1 and Im working with 8. Here's the link: VS Developer Express for Windows Phone new project shows XamlParseException
Any help would be greatly appreciated!
MainPage.xaml:
<phone:PhoneApplicationPage
x:Class="PetSounds.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>
<TextBlock Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Button Name="PlayAudioButton"
Height="200"
Width="200"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Background="Red"
Click="PlayAudioButton_Click_1">Quack</Button>
<MediaElement x:Name="QuackMediaElement"
Source="/Assets/Audio/Animals/Duck.wav"
Volume="1"
AutoPlay="False"
/>
</Grid>
</Grid>
</phone:PhoneApplicationPage>
EDIT
Here is the App.Xaml file:
<Application
x:Class="PetSounds.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone">
<!--Application Resources-->
<Application.Resources>
<local:LocalizedStrings xmlns:local="clr-namespace:PetSounds" x:Key="LocalizedStrings"/>
</Application.Resources>
<Application.ApplicationLifetimeObjects>
<!--Required object that handles lifetime events for the application-->
<shell:PhoneApplicationService
Launching="Application_Launching" Closing="Application_Closing"
Activated="Application_Activated" Deactivated="Application_Deactivated"/>
</Application.ApplicationLifetimeObjects>
</Application>
If needed let me know and I will post the other files.

How to replace fixed width and height on a custom windows phone control?

I want to make a control displaying three bitmap like this :
My problem is that I don't want to have fixed "Width" and "Height" for bitmap. They must take all available space where they are and keeping their aspects.
When I'am designing it with Blend, the designer always put fixed size....
Here is my code :
<UserControl x:Class=""
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
>
<Grid x:Name="LayoutRoot" Background="{StaticResource PhoneChromeBrush}">
<Image HorizontalAlignment="Left" Height="203" Margin="53,30,0,0" VerticalAlignment="Top" Source="/FakeData/Images/lavieestbelle.jpg" RenderTransformOrigin="0.5,0.5" Width="144" UseLayoutRounding="False" d:LayoutRounding="Auto">
<Image.RenderTransform>
<CompositeTransform Rotation="-15"/>
</Image.RenderTransform>
</Image>
<Image HorizontalAlignment="Left" Height="203" Margin="88,30,0,0" VerticalAlignment="Top" Source="/FakeData/Images/lavieestbelle.jpg" Width="144"/>
<Image HorizontalAlignment="Left" Height="203" Margin="132.951,34.5,0,0" VerticalAlignment="Top" Source="/FakeData/Images/lavieestbelle.jpg" RenderTransformOrigin="0.5,0.5" UseLayoutRounding="False" d:LayoutRounding="Auto" Width="144">
<Image.RenderTransform>
<CompositeTransform Rotation="15"/>
</Image.RenderTransform>
</Image>
</Grid>
How can I do that ? Thank for any help
Image.Stretch property can be helpful http://msdn.microsoft.com/en-us/library/system.windows.controls.image.stretch.aspx.

in windows phone,how to implement a android-like tabview like this?

the first picture is android's tabview
the second picture is android-like tabview which in the pivot control
tabview is in the pivot page’s grid
i'd like to have a result just like the second picture
any suggestions will be great!!!!!
thanks
<phone:PhoneApplicationPage
x:Class="ewlan.PivotMainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="False">
<Grid x:Name="LayoutRoot" Background="Transparent">
//what's in here?
//i know pivot
//what i need to know is what in the pivot.item
//hope u can know my meanings,any suggestions will be great
</Grid>
Well, if you create a new application and add a Pivot page, it will generate some pages in Pivot control. I suggest that you take a look at it and add the necessary controls. Take a look at the MSDN reference for more information. You will get something like this:
<!--LayoutRoot is the root grid where all page content is placed.-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<!--Pivot Control-->
<controls:Pivot Title="MY APPLICATION">
<!--Pivot item one-->
<controls:PivotItem Header="item1">
<Grid/>
</controls:PivotItem>
<!--Pivot item two-->
<controls:PivotItem Header="item2">
<Grid/>
</controls:PivotItem>
</controls:Pivot>
</Grid>
Pivot contains PivotItems which in turn contains your UI elements.