Stretch my buttons in a TopAppBar - xaml

I am developing a universal application in Visual Studio 2015 Community, but I have a problem in stretching my 3 buttons when I test my application on local PC or the Windows phone emulator, this is what I get with my code:
<CommandBar Height="51" >
<CommandBar.Content>
<Grid>
<StackPanel>
<Image x:Name="image1" Margin="41,10,-168,-50" Source="images/name.png" RenderTransformOrigin="0.487,0.82"/>
<Image x:Name="image" Margin="1,0,-40,-50" Source="images/icon.png"/>
</StackPanel>
<StackPanel>
<Button Height="49" Margin="0,0,-244,0" Width="35" HorizontalAlignment="Right" VerticalAlignment="Stretch">
<Button.Content>
<Image Source="images/home.png" Margin="-9,0.333,-9,-0.667"/>
</Button.Content>
</Button>
</StackPanel>
<StackPanel>
<Button Height="49" Margin="0,0,-280,0" Width="35" HorizontalAlignment="Right" VerticalAlignment="Stretch">
<Image Source="images/search.png" Margin="-9,0.333,-9,-0.667"/>
</Button>
</StackPanel>
<StackPanel>
<Button Height="49" Margin="0,0,-315,0" Width="35" HorizontalAlignment="Right" VerticalAlignment="Stretch">
<Image Source="images/profil.png" Margin="-9,0.333,-9,-0.667"/>
</Button>
</StackPanel>
</Grid>
</CommandBar.Content>
This what I want to get:

This is going to get you there:
<!--Content Alignment is left by default!-->
<CommandBar HorizontalContentAlignment="Stretch">
<CommandBar.Content>
<Grid>
<!--Left element-->
<Rectangle Margin="10" Height="35" Width="35" Fill="Red"
HorizontalAlignment="Left"/>
<!--Right elements together in a horizontal StackPanel-->
<StackPanel Orientation="Horizontal"
HorizontalAlignment="Right">
<Rectangle Margin="10" Height="35" Width="35" Fill="Red" />
<Rectangle Margin="10" Height="35" Width="35" Fill="Red" />
<Rectangle Margin="10" Height="35" Width="35" Fill="Red" />
</StackPanel>
</Grid>
</CommandBar.Content>
</CommandBar>

First up, you tagged your question inside several different area's, so it's difficult for us to tell what platform you are on. Is it a WinRT 8.1 app or a UWP windows 10 app?
But for reference, if it's a UWP Win10 app, first try to use following XAML, it creates a CommandBar with 1 primary command. And on the UWP platform that will position the icon at the right of the screen.
<CommandBar IsOpen="True" IsSticky="True">
<CommandBar.PrimaryCommands>
<AppBarButton Icon="Add" />
</CommandBar.PrimaryCommands>
</CommandBar>
More info on what and how items are displayed inside a commandbar can be found on MSDN here https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.commandbar.aspx

There are a few issues with what you're trying.
The XAML you have is more complicated than it needs to be.
You've tried to align controls by setting margins - this doesn't work with
variable sized containers.
You're not using any of the functionality of the CommandBar so you probably don't need it.
Instead you can make the layout you desire with a simple grid.:
<Grid VerticalAlignment="Top" Height="51">
<StackPanel HorizontalAlignment="Left">
<Image x:Name="image1" Source="images/name.png" />
<Image x:Name="image" Source="images/icon.png"/>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" >
<Button >
<Image Source="images/home.png" />
</Button>
<Button>
<Image Source="images/search.png" />
</Button>
<Button >
<Image Source="images/profil.png" />
</Button>
</StackPanel>
</Grid>

Related

Trying to arrange Ui Responsive to all uwp platform

I'm trying to arrange UI Responsive in all uwp platform But some issue arises
,I'm new to uwp development .Any idea how to implement look same in windows 10 mobile ,tabs and desktop.
Xaml code
<Grid Name="HomeView" >
<Grid.Background>
<ImageBrush ImageSource="Assets/Home/home_android.jpg"/>
</Grid.Background>
<StackPanel>
<MediaElement x:Name="mycontrol" Source="/Audio/bg_sound.mp3" AutoPlay="True"/>
</StackPanel>
<StackPanel>
<MediaElement x:Name="mediaElement1" />
</StackPanel>
<RelativePanel>
<Image Source="Assets/Home/btn_learn_colours.png"
HorizontalAlignment="Left"
VerticalAlignment="Bottom"
Margin="20,90,0,60"
Width="180" Height="200"
Tapped="L_color_tap"/>
<Image Source="Assets/Home/btn_paint.png"
HorizontalAlignment="Center"
VerticalAlignment="Bottom"
Margin="220,90,0,0"
Width="180" Height="200"
Tapped="Paint"/>
<Image Source="Assets/Home/btn_quiz_f.png"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Margin="440,60,0,0"
Width="180" Height="200"
Tapped="Quiz"/>
<Image Source="Assets/Home/btn_other_apps.png"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
Margin="440,140,0,0"
Width="180" Height="200"
Tapped="Other_Apps"/>
</RelativePanel>
</Grid>

Shadow effect to Image/StackPanel in Windows Universal App

How can I add shadow effect in Windows universal app?
I have added Image into StackPanel. I want to add shadow effect to that control (StackPanel).
I am trying to do something like below image.
This should give you the inspiration to arrive at something you like.
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid Width="100" Height="100" Margin="0,10">
<Image Source="PinkSquare.png" Width="95" Height="95" HorizontalAlignment="Right" VerticalAlignment="Bottom" Opacity="0.5"/>
<Image Source="PinkSquare.png" Width="95" Height="95" HorizontalAlignment="Left" VerticalAlignment="Top"/>
</Grid>
<Grid Width="100" Height="100" Margin="0,10">
<Image Source="GraySquare.png" Width="95" Height="95" HorizontalAlignment="Right" VerticalAlignment="Bottom" Opacity="0.5"/>
<Image Source="PinkSquare.png" Width="95" Height="95" HorizontalAlignment="Left" VerticalAlignment="Top"/>
</Grid>
</StackPanel>
Add borders, rounded corners, gradients, etc. to achieve the final look you like.

Windows Store Browse Button

I want to create a simple Browse button like that found on the Windows 8.1 Reader app:
However, after searching for an hour I'm still no wiser. There must be a standard Button style for circle buttons? And where would I find the browse icon?
Not sure this is the most elegant XAML in the world, but it gets the job done.
<Button Style="{StaticResource TextBlockButtonStyle}">
<Button.RenderTransform>
<ScaleTransform ScaleX="2" ScaleY="2" />
</Button.RenderTransform>
<Grid>
<Rectangle Fill="DimGray" />
<Grid Margin="7,5,5,5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="22" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="" FontFamily="Segoe UI Symbol" FontSize="18" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="0,-2,0,0" />
<TextBlock Grid.Column="0" Text="" FontFamily="Segoe UI Symbol" FontSize="12" VerticalAlignment="Center" HorizontalAlignment="Center" />
<TextBlock Grid.Column="1" Text="Browse" FontWeight="Light" Margin="4,0,0,0" VerticalAlignment="Center" HorizontalAlignment="Left" />
</Grid>
</Grid>
</Button>
Here's the result:
Best of luck!
you should see this
AppBar button style images
Symbol enumeration
Modern UI
Icons

Resize elements to fit the current screensize using XAML for WP 8.1

I'm making an app for Windows Phone 8.1 and I've run into some troubles with how the elements are displayed on the screen in different resolutions.
My question is: How can I display two columns with X number of rows, where the width of the columns will stretch to the side of the screen, no matter the screen size (for phones).
[1] Just to give you a visual example, this is how I want it to look, no matter the screen size (picture number [1]): (There are more rows below, but I removed them for this example).
http://imgur.com/a/DTYsg
[2] However, on bigger screens (this case a 6-inch), the content does not stretch all the way out, as shown in picture number [2].
[3] I've tried adding a Viewbox around the content, but then the result is like picture number [3] in the imgur link (couldn't upload more than one link). It stretches out, but it doesn't give me two columns. I've tried setting a max width for the Viewbox as well, but it doesn't change anything.
My XAML code so far is:
<ScrollViewer>
<Grid>
<GridView x:Name="ContentGrid" Margin="0,5,0,5" HorizontalAlignment="Center">
<GridView.Header>
<TextBlock TextWrapping="Wrap" Margin="0,5,0,5" HorizontalAlignment="Center" Text="Application name" Style="{StaticResource HeaderStyle}" />
</GridView.Header>
<!-- Row 1 -->
<GridViewItem Tapped="GridViewItem_Tapped_1" Style="{StaticResource GridStyleOdd}">
<Grid>
<Image Height="70" Width="70" HorizontalAlignment="Center" VerticalAlignment="Center" Source="Assets/Icons/Angle.png" Margin="0,-9,5,9" />
<TextBlock Text="Angle" Style="{StaticResource TextBlockStyle}" />
</Grid>
</GridViewItem>
<GridViewItem Tapped="GridViewItem_Tapped_1" Style="{StaticResource GridStyleOdd}">
<Grid>
<Image Height="70" Width="70" HorizontalAlignment="Center" VerticalAlignment="Center" Source="Assets/Icons/Area.png" Margin="0,-9,5,9" />
<TextBlock Text="Area" Style="{StaticResource TextBlockStyle}" />
</Grid>
</GridViewItem>
<!-- Row 2 -->
<GridViewItem Style="{StaticResource GridStyleEven}">
<Grid>
<Image Height="70" Width="70" HorizontalAlignment="Center" VerticalAlignment="Center" Source="Assets/Icons/Fuel_Consumption.png" Margin="0,-9,5,9" />
<TextBlock Text="Consumption" Style="{StaticResource TextBlockStyle}" Margin="10,0,0,-23" Width="188" />
</Grid>
</GridViewItem>
<GridViewItem Tapped="GridViewItem_Tapped_2" Style="{StaticResource GridStyleEven}">
<Grid>
<Image Height="70" Width="70" HorizontalAlignment="Center" VerticalAlignment="Center" Source="Assets/Icons/Currency.png" Margin="0,-9,5,9" />
<TextBlock Text="Currency" Style="{StaticResource TextBlockStyle}" />
</Grid>
</GridViewItem>
</GridView>
</Grid>
</ScrollViewer>
Thank you!
You can change the size of one from the GridViewItems in code behind
e.x.
public MainPage()
{
//....
var bounds = Window.Current.Bounds;
double height = bounds.Height;
double width = bounds.Width;
gridViewitem1.Width = width * 0.5f;
ContentGrid.Width = width;
}
I've tested it on all sizes.
EDIT:
You must change the width of the ContentGrid, too.
And remove the grid, wich is in the Scrollviewer
<ScrollViewer>
<GridView x:Name="ContentGrid" Margin="0,5,0,5" HorizontalAlignment="Center">
<GridView.Header>
<TextBlock TextWrapping="Wrap" Margin="0,5,0,5" HorizontalAlignment="Center" Text="Application name" Style="{StaticResource HeaderStyle}" />
</GridView.Header>
<!-- Row 1 -->
<GridViewItem x:Name="gridViewItem1" Tapped="GridViewItem_Tapped_1" Style="{StaticResource GridStyleOdd}">
<Grid>
<Image Height="70" Width="70" HorizontalAlignment="Center" VerticalAlignment="Center" Source="Assets/Icons/Angle.png" Margin="0,-9,5,9" />
<TextBlock Text="Angle" Style="{StaticResource TextBlockStyle}" />
</Grid>
</GridViewItem>
<GridViewItem Tapped="GridViewItem_Tapped_1" Style="{StaticResource GridStyleOdd}">
<Grid>
<Image Height="70" Width="70" HorizontalAlignment="Center" VerticalAlignment="Center" Source="Assets/Icons/Area.png" Margin="0,-9,5,9" />
<TextBlock Text="Area" Style="{StaticResource TextBlockStyle}" />
</Grid>
</GridViewItem>
<!-- Row 2 -->
<GridViewItem Style="{StaticResource GridStyleEven}">
<Grid>
<Image Height="70" Width="70" HorizontalAlignment="Center" VerticalAlignment="Center" Source="Assets/Icons/Fuel_Consumption.png" Margin="0,-9,5,9" />
<TextBlock Text="Consumption" Style="{StaticResource TextBlockStyle}" Margin="10,0,0,-23" Width="188" />
</Grid>
</GridViewItem>
<GridViewItem Tapped="GridViewItem_Tapped_2" Style="{StaticResource GridStyleEven}">
<Grid>
<Image Height="70" Width="70" HorizontalAlignment="Center" VerticalAlignment="Center" Source="Assets/Icons/Currency.png" Margin="0,-9,5,9" />
<TextBlock Text="Currency" Style="{StaticResource TextBlockStyle}" />
</Grid>
</GridViewItem>
</GridView>

Problems with Buttons in a Scrollviewer

I'm trying to add Buttons to my Scrollviewer, my result so far is negative, scrollviewer will not work. I tried wrapping around stackpanels but no luck. Can anyone guide me in the right direction? Thanks,
<ScrollViewer Name="flippy" Grid.Row="1" >
<Grid Width="Auto" Height="Auto" MinWidth="1366" MinHeight="668" Name="GridA" Grid.Row="1">
<Image HorizontalAlignment="Center" VerticalAlignment="Center" Source="ms-appx:///Assets/Pics/Alfabetet/Appelsin.png" Stretch="None" />
<StackPanel Height="150" Width="Auto" HorizontalAlignment="Center" VerticalAlignment="Top" Orientation="Horizontal">
<Button Content="button1" HorizontalAlignment="Left" VerticalAlignment="Center" Height="180" Width="179" Margin="10">
<Button.Background>
<ImageBrush ImageSource="ms-appx:///Assets/Pics/Alfabetet/storA.png"></ImageBrush>
</Button.Background>
</Button>
<Button Content="button2" HorizontalAlignment="Right" VerticalAlignment="Center" Height="140" Width="121" Margin="10">
<Button.Background>
<ImageBrush ImageSource="ms-appx:///Assets/Pics/Alfabetet/litenA.png"/>
</Button.Background>
</Button>
</StackPanel>
<StackPanel Height="103" Width="557" VerticalAlignment="Bottom" HorizontalAlignment="Center" Orientation="Horizontal">
<Button Content="button3" HorizontalAlignment="Center" VerticalAlignment="Center" Height="103" Width="553">
<Button.Background>
<ImageBrush ImageSource="ms-appx:///Assets/Pics/Alfabetet/Appelsin.fw.png"/>
</Button.Background>
</Button>
<Image Source="ms-appx:///Assets/Pics/Alfabetet/Appelsin.fw.png" />
</StackPanel>
</Grid>
</ScrollViewer>