Switching between landscape and portrait mode using wpf in tablet devices - c#

How could we arrange the controls on a WPF window so that it would automatically align the controls while switching between view modes occur ie between landscape and portrait mode.
<Window x:Class="Custom_Track_Reports.LoginWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="LoginWindow" >
<Viewbox Stretch="Fill">
<Grid Background="#FF58B0DF" Height="401">
<Rectangle Fill="#FFF0F3F4" Height="173" Margin="45,197,58,0" Stroke="Black" VerticalAlignment="Top" AllowDrop="True" />
<Image Height="125" Margin="340,10,330,0" VerticalAlignment="Top" Source="Images/logo_lrg.png"/>
<Label Content="Custom Track Reports" HorizontalAlignment="Left" Margin="287,147,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.607,1.112" Width="268" Height="47" FontFamily="Arial" FontSize="26" Foreground="White"/>
<TextBox Margin="128,0,0,110" TextWrapping="Wrap" VerticalAlignment="Bottom" Height="25" BorderThickness="1" FontFamily="Arial" FontSize="21" Text="" Name="userTextBox" FontStretch="Expanded" Opacity="1" HorizontalAlignment="Left" Width="546" AcceptsReturn="False" KeyDown="userTextBox_KeyDown" />
<Button x:Name="enterButton" Content="Enter" HorizontalAlignment="Right" Margin="0,311,166,0" VerticalAlignment="Top" Width="110" Height="26" FontSize="14" Style="{DynamicResource button}" Click="enterButton_Click"/>
<Label Content="User ID" FontSize="20" FontWeight="Bold" Height="40" HorizontalAlignment="Left" Margin="122,215,0,0" Name="label1" VerticalAlignment="Top" Width="105" />
</Grid>
</Viewbox>

Related

keydown no longer working after adding a ribbon control to a wpf window

I have a strange problem, I had a WPF (with C# code behind) page with some buttons and some keydown events. Recently I've added a ribbon control to group the buttons and the keydown events aren't working any more.
The strangest thing is that if I add back any of the old buttons (outside of the ribbon) and click on it then the keydown events start working.
Thanks
<Page x:Class="Ab3d.PowerToys.Samples.SceneEditor.SceneEditor"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ribbon="clr-namespace:System.Windows.Controls.Ribbon;assembly=System.Windows.Controls.Ribbon"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:cameras="clr-namespace:Ab3d.Cameras;assembly=Ab3d.PowerToys"
xmlns:ab3d="clr-namespace:Ab3d.Controls;assembly=Ab3d.PowerToys"
xmlns:visuals="clr-namespace:Ab3d.Visuals;assembly=Ab3d.PowerToys"
xmlns:local="clr-namespace:Ab3d.PowerToys.Samples.SceneEditor"
mc:Ignorable="d"
d:DesignHeight="550" d:DesignWidth="800"
Title="SceneEditor" KeyDown="MainViewport_KeyDown" PreviewKeyDown="Window_PreviewKeyDown"
ShowsNavigationUI="False" >
<Page.Resources>
<BooleanToVisibilityConverter x:Key="VisibilityOfBool" />
<DiffuseMaterial x:Key="Material1" Brush ="Coral" />
</Page.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid Name="OptionsGrid" Grid.Row="0" Margin="0 0 0 10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<!-- THE RIBBON -->
<ribbon:Ribbon SelectedIndex="0" KeyDown="MainViewport_KeyDown">
<!-- Tab -->
<RibbonTab Header="Model" HorizontalAlignment="Left" Height="88" VerticalAlignment="Top" Width="1000">
<!-- Draw -->
<RibbonGroup Header="Draw" Height="88" Margin="0" VerticalAlignment="Top" Width="280">
<RibbonButton x:Name="Point"
Label="Point"
LargeImageSource="C:\Users\Infra-Iordanescu\source\repos\ARES\Images\PointRo.png"
HorizontalAlignment="Left"
Height="60"
Margin="0,5,0,0"
VerticalAlignment="Top"
Width="20"
Click="NewPointButton_Click"/>
<RibbonButton x:Name="NewLine"
Label="Line"
LargeImageSource="C:\Users\Infra-Iordanescu\source\repos\ARES\Images\NewLine2.png"
HorizontalAlignment="Left"
Height="60"
Margin="0,5,0,0"
VerticalAlignment="Top"
Width="20"
Click="NewLineButton_Click"/>
<RibbonButton x:Name="Arc"
Label="Arc"
LargeImageSource="C:\Users\Infra-Iordanescu\source\repos\ARES\Images\Arc2.png"
HorizontalAlignment="Left"
Height="60"
Margin="0,5,0,0"
VerticalAlignment="Top"
Width="20"
Click="NewPointButton_Click"/>
<RibbonButton x:Name="Surface"
Label="Surface"
LargeImageSource="C:\Users\Infra-Iordanescu\source\repos\ARES\Images\Surface2.png"
HorizontalAlignment="Left"
Height="60"
Margin="0,5,0,0"
VerticalAlignment="Top"
Width="20"
Click="NewPointButton_Click"/>
<RibbonButton x:Name="Volume"
Label="Volume"
LargeImageSource="C:\Users\Infra-Iordanescu\source\repos\ARES\Images\Volume2.png"
HorizontalAlignment="Left"
Height="60"
Margin="0,5,0,0"
VerticalAlignment="Top"
Width="60"
Click="NewPointButton_Click"/>
<StackPanel>
<RibbonButton x:Name="Clothoid"
SmallImageSource="C:\Users\Infra-Iordanescu\source\repos\ARES\Images\Clothoid2.png"
HorizontalAlignment="Left"
Height="20"
Margin="0,5,0,0"
VerticalAlignment="Top"
Width="22"
Click="NewPointButton_Click"/>
<RibbonButton x:Name="Spline"
SmallImageSource="C:\Users\Infra-Iordanescu\source\repos\ARES\Images\Spline2.png"
HorizontalAlignment="Left"
Height="25"
Margin="0,0,0,0"
VerticalAlignment="Top"
Width="22"
Click="NewPointButton_Click"/>
<RibbonButton x:Name="Ellipse"
SmallImageSource="C:\Users\Infra-Iordanescu\source\repos\ARES\Images\Ellipse2.png"
HorizontalAlignment="Left"
Height="24"
Margin="0,0,0,0"
VerticalAlignment="Top"
Width="22"
Click="NewPointButton_Click"/>
</StackPanel>
</RibbonGroup>
<!-- Transform -->
<RibbonGroup Header="Transform" Height="88" Margin="0" VerticalAlignment="Top" Width="140">
<StackPanel>
<RibbonButton x:Name="Move"
Label="Move"
SmallImageSource="C:\Users\Infra-Iordanescu\source\repos\ARES\Images\Move.png"
HorizontalAlignment="Left"
Height="20"
Margin="0,0,0,0"
VerticalAlignment="Top"
Width="60"
Click="NewPointButton_Click"/>
<RibbonButton x:Name="Copy"
Label="Copy"
SmallImageSource="C:\Users\Infra-Iordanescu\source\repos\ARES\Images\Copy3.png"
HorizontalAlignment="Left"
Height="30"
Margin="0,0,0,0"
VerticalAlignment="Top"
Width="60"
Click="NewPointButton_Click"/>
<RibbonButton x:Name="Rotate"
Label="Rotate"
SmallImageSource="C:\Users\Infra-Iordanescu\source\repos\ARES\Images\Rotate2.png"
HorizontalAlignment="Left"
Height="20"
Margin="0,0,0,0"
VerticalAlignment="Top"
Width="60"
Click="NewPointButton_Click"/>
</StackPanel>
<StackPanel>
<RibbonButton x:Name="Mirror"
Label="Mirror"
SmallImageSource="C:\Users\Infra-Iordanescu\source\repos\ARES\Images\Mirror.png"
HorizontalAlignment="Left"
Height="20"
Margin="10,0,0,0"
VerticalAlignment="Top"
Width="60"
Click="NewPointButton_Click"/>
<RibbonButton x:Name="Scale"
Label="Scale"
SmallImageSource="C:\Users\Infra-Iordanescu\source\repos\ARES\Images\Scale.png"
HorizontalAlignment="Left"
Height="30"
Margin="10,0,0,0"
VerticalAlignment="Top"
Width="60"
Click="NewPointButton_Click"/>
<RibbonButton x:Name="Array"
Label="Array"
SmallImageSource="C:\Users\Infra-Iordanescu\source\repos\ARES\Images\Array.png"
HorizontalAlignment="Left"
Height="20"
Margin="10,0,0,0"
VerticalAlignment="Top"
Width="60"
Click="NewPointButton_Click"/>
</StackPanel>
</RibbonGroup>
<!-- Loads -->
<RibbonGroup Header="Loads" Height="88" Margin="0" VerticalAlignment="Top" Width="160">
<RibbonButton x:Name="Nodal"
Label="Nodal"
LargeImageSource="C:\Users\Infra-Iordanescu\source\repos\ARES\Images\NoadalLoads.png"
HorizontalAlignment="Left"
Height="60"
Margin="0,5,0,0"
VerticalAlignment="Top"
Width="50"
Click="NewPointButton_Click"/>
<RibbonButton x:Name="UDL"
Label="UDL"
LargeImageSource="C:\Users\Infra-Iordanescu\source\repos\ARES\Images\UDL.png"
HorizontalAlignment="Left"
Height="60"
Margin="0,5,0,0"
VerticalAlignment="Top"
Width="50"
Click="NewPointButton_Click"/>
<RibbonButton x:Name="Face"
Label="Face"
LargeImageSource="C:\Users\Infra-Iordanescu\source\repos\ARES\Images\Face.png"
HorizontalAlignment="Left"
Height="60"
Margin="0,5,0,0"
VerticalAlignment="Top"
Width="45"
Click="NewPointButton_Click"/>
</RibbonGroup>
<RibbonGroup Header="Analysis" Height="88" Margin="0" VerticalAlignment="Top" Width="100"/>
<RibbonGroup Header="Results" Height="88" Margin="0" VerticalAlignment="Top" Width="100"/>
<RibbonGroup Header="View" Height="88" Margin="0" VerticalAlignment="Top" Width="100"/>
</RibbonTab>
<RibbonTab Header="Prop" HorizontalAlignment="Left" Height="88" VerticalAlignment="Top" Width="798"/>
</ribbon:Ribbon>
<StackPanel Grid.Column="0" Orientation="Horizontal" Margin="10 0 0 0">
<!-- <StackPanel Orientation="Vertical">
<Button Name="ResetCameraCenterButton" Content="Reset camera" ToolTip="Sets camera TargetPosition to (0,0,0)" VerticalAlignment="Center" Click="ResetCameraCenterButton_Click" Margin="0 0 5 0"/>
<Button Name="FitViewButton" Content="Fit to view" Click="FitViewButton_Click" VerticalAlignment="Center" Margin="0 5 5 0" />
</StackPanel> -->
</StackPanel>
<!-- <StackPanel Grid.Column="1" Orientation="Vertical" Margin="10 0 0 0">
<Button Name="newPoint" Content="Point" ToolTip="New Point" VerticalAlignment="Center" Click="NewPointButton_Click" Margin="0 0 5 0"/>
<Button Name="newLine" Content="Line" ToolTip="New Line (L)" VerticalAlignment="Center" Click="NewLineButton_Click" Margin="0 5 5 0"/>
</StackPanel> -->
</Grid>
<Border Name="ViewportBorder" Grid.Row="1" Background="White"
MouseMove="ViewportBorder_MouseMove" >
<Viewport3D Name="MainViewport">
<ModelVisual3D x:Name="VisualSpace" />
<visuals:WireGridVisual3D x:Name="MainWireGrid"
CenterPosition="0 0 0"
Size="200 200"
WidthCellsCount="25"
HeightCellsCount="25"
LineColor="#555555"
LineThickness="1"
MajorLinesFrequency="5"
MajorLineThickness="2"
MajorLineColor="#333333"
IsVisible="{Binding Source={x:Static local:SceneEditorContext.Current}, Path=ShowWireGrid}" />
<ModelVisual3D x:Name="ObjectsVisual" />
</Viewport3D>
</Border>
<cameras:TargetPositionCamera Name="Camera1" Grid.Row="1"
TargetPosition="0 0 0"
Heading="30" Attitude="-30" Bank="0"
Distance="300"
ShowCameraLight="Always"
TargetViewport3D="{Binding ElementName=MainViewport}"/>
<ab3d:MouseCameraController Name="MouseCameraController1" Grid.Row="1"
ShowRotationCenterMarker="True"
ZoomMode="MousePosition"
RotateCameraConditions="RightMouseButtonPressed"
MoveCameraConditions="MiddleMouseButtonPressed"
EventsSourceElement="{Binding ElementName=ViewportBorder}"
TargetCamera="{Binding ElementName=Camera1}" />
<ab3d:CameraAxisPanel Grid.Row="1" VerticalAlignment="Bottom" HorizontalAlignment="Left"
TargetCamera="{Binding ElementName=Camera1}"
Visibility="{Binding Source={x:Static local:SceneEditorContext.Current}, Path=ShowCameraAxis, Converter={StaticResource VisibilityOfBool}}"/>
<ab3d:ViewCubeCameraController Grid.Row="1" VerticalAlignment="Bottom" HorizontalAlignment="Right"
TargetCamera="{Binding ElementName=Camera1}"
Visibility="{Binding Source={x:Static local:SceneEditorContext.Current}, Path=ShowViewCubeCameraController, Converter={StaticResource VisibilityOfBool}}" />
<ab3d:MouseCameraControllerInfo Name="MouseCameraControllerInfo1" Grid.Row="1" Margin="0 5 0 0"
VerticalAlignment="Top" HorizontalAlignment="Right"
MouseCameraController="{Binding ElementName=MouseCameraController1}"
Visibility="{Binding Source={x:Static local:SceneEditorContext.Current}, Path=ShowMouseCameraControllerInfo, Converter={StaticResource VisibilityOfBool}}" />
<!-- Selection canvas -->
<Canvas Name="SelectionOverlayCanvas" Grid.Column="0" IsHitTestVisible="False">
<Rectangle Name="SelectionRectangle" Fill="#555FD3FF" Stroke="#AA5FD3FF" StrokeThickness="1" Visibility="Collapsed" />
</Canvas>
<!-- Point data tooltip -->
<Canvas Name="DataToolTipCanvas" Grid.Column="0" IsHitTestVisible="False">
<Border Name="DataToolTipBorder" BorderThickness="2" BorderBrush="Black" Background="LightGray" Visibility="Collapsed">
<StackPanel Orientation="Vertical">
<TextBlock Text="Coordinates:" />
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding X, StringFormat={}X:{0:N}}"/>
<TextBlock Text="{Binding Y, StringFormat={} Y:{0:N}}"/>
<TextBlock Text="{Binding Z, StringFormat={} Z:{0:N}}"/>
</StackPanel>
</StackPanel>
</Border>
</Canvas>
</Grid>
</Page>
private void MainViewport_KeyDown(object sender, KeyEventArgs e)
{
System.Diagnostics.Debug.WriteLine("KeyDown");
// ESC deselects all
if (e.Key == Key.Escape)
{
for (var i = 0; i < spheres.Count; i++)
{
spheres[i].Material = material;
spheres[i].Radius = originalRadius;
}
for (var i = 0; i < lines.Count; i++)
{
lines[i].LineColor = originalLineColor;
}
DataToolTipBorder.Visibility = Visibility.Collapsed;
this.DataContext = null;
}
The problem has been solved, by:
Loaded="Page_Loaded" Focusable="True"
and
private void Page_Loaded(object sender, RoutedEventArgs e)
{
this.Focus();
}
It seems it was a focus issue.
Thanks.

Image to fit screen size in WPF

I am trying to make an image stretch to fit the screen with preserverd aspect ratio. I thought this code would do the trick:
<Image Name="Viewer" Height="{Binding SystemParameters.PrimaryScreenHeight}" Width="{Binding SystemParameters.PrimaryScreenHeight}" Stretch="Uniform" StretchDirection="Both"/>
Regretably it seems like the image just fits to the width of the screen and crops it at the bottom.
The complete xaml code looks like this:
enter co<Window x:Class="ImageExplorer.MainWindow"
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"
xmlns:local="clr-namespace:ImageExplorer"
mc:Ignorable="d"
Title="MainWindow" WindowState="Maximized" Background="Black">
<StackPanel>
<Border BorderBrush="Black" BorderThickness="2">
<Grid Margin="0,0,0,0">
<Button Content="open" Click="OpenImage" HorizontalAlignment="Left" VerticalAlignment="Center" Width="58" Height="30" Margin="1,1,1,1" />
<Button Content="Prev." Click="GetPreviousImage" HorizontalAlignment="Left" VerticalAlignment="Center" Width="58" Height="30" Margin="120,1,1,1"/>
<Button Content="Next" Click="GetNextImage" HorizontalAlignment="Left" VerticalAlignment="Center" Width="58" Height="30" Margin="180,1,1,1" />
<Label Content="Fil:" HorizontalAlignment="Right" VerticalAlignment="Center" Width="120" Height="30" Margin="1,1,300,1"/>
<TextBlock Name="StiViser" HorizontalAlignment="Right" VerticalAlignment="Center" Width="298" Margin="1,1,1,1" TextWrapping="Wrap" Text="TextBlock"/>
</Grid>
</Border>
<Image Name="Viewer" Height="{Binding SystemParameters.PrimaryScreenHeight}" Width="{Binding SystemParameters.PrimaryScreenWidth}" Stretch="Uniform" StretchDirection="Both"/>
</StackPanel>
Use DockPanel instead
<DockPanel LastChildFill="True">
<Border DockPanel.Dock="Top" BorderBrush="Black" BorderThickness="2">
<Grid Margin="0,0,0,0">
<Button Content="open" Click="OpenImage" HorizontalAlignment="Left" VerticalAlignment="Center" Width="58" Height="30" Margin="1,1,1,1" />
<Button Content="Prev." Click="GetPreviousImage" HorizontalAlignment="Left" VerticalAlignment="Center" Width="58" Height="30" Margin="120,1,1,1"/>
<Button Content="Next" Click="GetNextImage" HorizontalAlignment="Left" VerticalAlignment="Center" Width="58" Height="30" Margin="180,1,1,1" />
<Label Content="Fil:" HorizontalAlignment="Right" VerticalAlignment="Center" Width="120" Height="30" Margin="1,1,300,1"/>
<TextBlock Name="StiViser" HorizontalAlignment="Right" VerticalAlignment="Center" Width="298" Margin="1,1,1,1" TextWrapping="Wrap" Text="TextBlock"/>
</Grid>
</Border>
<Image Name="Viewer" Height="{Binding SystemParameters.PrimaryScreenHeight}" Width="{Binding SystemParameters.PrimaryScreenWidth}" Stretch="Fill" StretchDirection="Both"/>
</DockPanel>

Textboxes don't work Windows Phone 8.1 App

I am not able to have a user input in a textbox when click it both in the Emulator and in windows phone device. I have deleted all the textboxes and replace them with new ones without any special preferences and still don't work. I have implemented the whole interface of my application and need help to solve this issue and start playing with the server connection. Also the rest of the controls all work properly. Please any ideas?
This is the corresponding interface of the code I am posting below.
This is my mainpage.xaml code: If you need anything else please let me know.
<controls:ViewPage
x:Class="Menu_and_Topbar_app__Windows_Phone_8._1_3.MainPage"
xmlns:controls="using:Menu_and_Topbar_app__Windows_Phone_8._1_3.Controls"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Menu_and_Topbar_app__Windows_Phone_8._1_3"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="#FF250D5C">
<ScrollViewer HorizontalAlignment="Center"
VerticalAlignment="Center"
Margin="5.857,6.897,8.265,12.783" RenderTransformOrigin="0.5,0.5" Height="620.32" UseLayoutRounding="False" Width="385.878" d:LayoutRounding="Auto">
<ScrollViewer.RenderTransform>
<CompositeTransform Rotation="0.309"/>
</ScrollViewer.RenderTransform>
<Pivot Name="MyPivot" IsEnabled="True" IsTapEnabled="True">
<Pivot.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" FontSize="37" SelectionHighlightColor="#FF898888" />
</DataTemplate>
</Pivot.HeaderTemplate>
<PivotItem x:Name="PivotItem1" Header="Sign In" IsEnabled="True" IsTapEnabled="True">
<Grid HorizontalAlignment="Left" Height="496" Margin="18,19,0,0" VerticalAlignment="Top" Width="311" IsTapEnabled="True" IsRightTapEnabled="True">
<Image x:Name="image" HorizontalAlignment="Left" Height="70" Margin="64,9,0,0" VerticalAlignment="Top" Width="193" Source="/Menu and Topbar app (Windows Phone 8.1)3/Pictures/logo.png" Visibility="Visible" />
<Button x:Name="button" Content="Log In" HorizontalAlignment="Left" Margin="98,409,0,0" VerticalAlignment="Top" Click="button_Click_1"/>
<TextBlock x:Name="textBlock" HorizontalAlignment="Left" Margin="16,113,0,0" TextWrapping="Wrap" Text="Username or Email:" VerticalAlignment="Top" FontSize="16"/>
<TextBlock x:Name="textBlock2" HorizontalAlignment="Left" Margin="16,210,0,0" TextWrapping="Wrap" Text="Password:" VerticalAlignment="Top" FontSize="16"/>
<HyperlinkButton Content="Sign Up for SCP?" HorizontalAlignment="Left" Margin="17,266,0,0" VerticalAlignment="Top" FontSize="13.333" NavigateUri="http://scponline.azurewebsites.net/Home/LoginPartialView"/>
<CheckBox x:Name="checkBox" Content="Remember me?" HorizontalAlignment="Left" Margin="17,312,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="textBox" HorizontalAlignment="Left" Margin="17,137,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="275" GotFocus="textBox_GotFocus" AllowDrop="True" />
</Grid>
</PivotItem>
<PivotItem x:Name="PivotItem2" Header="Sign Up" >
<Grid HorizontalAlignment="Left" Height="496" Margin="18,19,0,0" VerticalAlignment="Top" Width="311">
<Button Content="Sign Up" HorizontalAlignment="Left" Margin="97,437,0,0" VerticalAlignment="Top" Click="Button_Click_2"/>
<TextBlock x:Name="textBlock3" HorizontalAlignment="Left" Margin="16,108,0,0" TextWrapping="Wrap" Text="Email:" VerticalAlignment="Top" FontSize="16"/>
<TextBlock x:Name="textBlock4" HorizontalAlignment="Left" Margin="16,168,0,0" TextWrapping="Wrap" Text="Password:" VerticalAlignment="Top" FontSize="16"/>
<TextBox x:Name="textBox3" HorizontalAlignment="Left" Margin="16,126,0,0" TextWrapping="Wrap" Text="username#mail.com" VerticalAlignment="Top" Height="0" Width="276" FontSize="17.593" RenderTransformOrigin="0.5,0.5">
<TextBox.RenderTransform>
<CompositeTransform ScaleY="0.9"/>
</TextBox.RenderTransform>
</TextBox>
<TextBox x:Name="textBox4" HorizontalAlignment="Left" Margin="16,187,0,0" TextWrapping="Wrap" Text="***********" VerticalAlignment="Top" Height="0" Width="276" TextChanged="textBox2_TextChanged" FontSize="17.593" RenderTransformOrigin="0.5,0.5">
<TextBox.RenderTransform>
<CompositeTransform ScaleY="0.9"/>
</TextBox.RenderTransform>
</TextBox>
<Image x:Name="image1" HorizontalAlignment="Left" Height="70" Margin="64,9,0,0" VerticalAlignment="Top" Width="193" Source="/Menu and Topbar app (Windows Phone 8.1)3/Pictures/logo.png"/>
<TextBlock x:Name="textBlock1" HorizontalAlignment="Left" Margin="16,232,0,0" TextWrapping="Wrap" Text="Name:" VerticalAlignment="Top" SelectionChanged="textBlock1_SelectionChanged" FontSize="16"/>
<TextBox x:Name="textBox5" HorizontalAlignment="Left" Margin="16,250,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="0" Width="276" TextChanged="textBox2_TextChanged" FontSize="17.593" RenderTransformOrigin="0.5,0.5">
<TextBox.RenderTransform>
<CompositeTransform ScaleY="0.9"/>
</TextBox.RenderTransform>
</TextBox>
<TextBlock x:Name="textBlock5" HorizontalAlignment="Left" Margin="16,292,0,0" TextWrapping="Wrap" Text="Name:" VerticalAlignment="Top" SelectionChanged="textBlock1_SelectionChanged" FontSize="16"/>
<TextBox x:Name="textBox6" HorizontalAlignment="Left" Margin="16,310,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="0" Width="276" TextChanged="textBox2_TextChanged" FontSize="17.593" RenderTransformOrigin="0.5,0.5">
<TextBox.RenderTransform>
<CompositeTransform ScaleY="0.9"/>
</TextBox.RenderTransform>
</TextBox>
</Grid>
</PivotItem>
</Pivot>
</ScrollViewer>
</Grid>

XAML for Windows Phone 7

I am building an app in Windows Phone 7.
I am showing a few data in different TextBlocks.
But as the data size is too big, it doesn't fit in my view.
I want to show the data like a paragraph.
If the data size exceeds the size of the emulator I want to put a ScrollBar so that the data can be scrolled and viewed.
Please help me.
I am providing my XAML design.
<Grid x:Name="ContentPanel" Margin="12,17,12,0" Grid.RowSpan="2">
<TextBlock TextAlignment="Center" Height="63" HorizontalAlignment="Right" Margin="0,6,43,0" Name="textBlock1" Text="News Details" VerticalAlignment="Top" Width="308" FontFamily="Verdana" FontSize="48" Foreground="AntiqueWhite"/>
<TextBlock Height="46" HorizontalAlignment="Left" Margin="45,333,0,0" Name="date" Text="" VerticalAlignment="Top" Width="173" FontFamily="Verdana" FontSize="24" />
<TextBlock Height="43" HorizontalAlignment="Left" Margin="45,397,0,0" Name="title" Text="" VerticalAlignment="Top" Width="373" />
<TextBlock Height="206" HorizontalAlignment="Left" Margin="45,462,0,0" Name="description" Text="" VerticalAlignment="Top" Width="373" />
<Image Height="167" HorizontalAlignment="Left" Margin="45,113,0,0" Name="newsimage" Stretch="Fill" VerticalAlignment="Top" Width="368" />
</Grid>
<Button x:Name="previous" BorderThickness="0" Click="Image_Back" Margin="0,23,431,682" HorizontalAlignment="Right" Width="76" Height="63" Grid.RowSpan="2">
<Button.Background>
<ImageBrush Stretch="Fill" ImageSource="Image/Previous.png" />
</Button.Background>
</Button>
</Grid>
Try this,
<Grid x:Name="ContentPanel" Margin="12,17,12,0" Grid.RowSpan="2">
<ScrollViewer HorizontalScrollBarVisibility="Auto">
<Grid VerticalAlignment="Top" HorizontalAlignment="Left">
<TextBlock TextWrapping="Wrap" TextAlignment="Center" Height="63" HorizontalAlignment="Right" Margin="0,6,43,0" Name="textBlock1" Text="News Details" VerticalAlignment="Top" Width="308" FontFamily="Verdana" FontSize="48" Foreground="AntiqueWhite"/>
<TextBlock TextWrapping="Wrap" Height="46" HorizontalAlignment="Left" Margin="45,333,0,0" Name="date" Text="" VerticalAlignment="Top" Width="173" FontFamily="Verdana" FontSize="24" />
<TextBlock TextWrapping="Wrap" Height="43" HorizontalAlignment="Left" Margin="45,397,0,0" Name="title" Text="" VerticalAlignment="Top" Width="373" />
<TextBlock TextWrapping="Wrap" Height="206" HorizontalAlignment="Left" Margin="45,462,0,0" Name="description" Text="" VerticalAlignment="Top" Width="373" />
<Image Height="167" HorizontalAlignment="Left" Margin="45,113,0,0" Name="newsimage" Stretch="Fill" VerticalAlignment="Top" Width="368" />
</Grid>
</ScrollViewer>
</Grid>
More details
http://msdn.microsoft.com/en-us/library/system.windows.controls.scrollviewer(v=vs.110).aspx
http://dotnet.dzone.com/news/scrollviewer-not-scrollable
Try using Scrollable textblock. Hope that help you to solve the issue.

Ispost back like functionality in WPF pages

I am building a WPF application which contains a large number of pages. I want to know whether there is any function which is similar to IsPostBack in Asp.Net. I just wanted to know is this the first time the specific page is loading. Thanks in advance.
xaml
<Window x:Class="Custom_Track_Reports.LoginWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="LoginWindow" >
<Viewbox Stretch="Fill">
<Grid Background="#FF58B0DF" Height="401">
<Rectangle Fill="#FFF0F3F4" Height="173" Margin="45,197,58,0" Stroke="Black" VerticalAlignment="Top" AllowDrop="True" />
<Image Height="125" Margin="340,10,330,0" VerticalAlignment="Top" Source="Images/logo_lrg.png"/>
<Label Content="Custom Track Reports" HorizontalAlignment="Left" Margin="287,147,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.607,1.112" Width="268" Height="47" FontFamily="Arial" FontSize="26" Foreground="White"/>
<TextBox Margin="128,0,0,110" TextWrapping="Wrap" VerticalAlignment="Bottom" Height="25" BorderThickness="1" FontFamily="Arial" FontSize="21" Text="" Name="userTextBox" FontStretch="Expanded" Opacity="1" HorizontalAlignment="Left" Width="546" AcceptsReturn="False" KeyDown="userTextBox_KeyDown" />
<Button x:Name="enterButton" Content="Enter" HorizontalAlignment="Right" Margin="0,311,166,0" VerticalAlignment="Top" Width="110" Height="26" FontSize="14" Style="{DynamicResource button}" Click="enterButton_Click"/>
<Label Content="User ID" FontSize="20" FontWeight="Bold" Height="40" HorizontalAlignment="Left" Margin="122,215,0,0" Name="label1" VerticalAlignment="Top" Width="105" />
</Grid>
</Viewbox>
If your page navigation is taking place via Frame, then attach to the Frame.Navigated event. If you provide more detail (some XAML and code) then we might be able to be more helpful...

Categories