Exception occured on intalizied object in window phone 8 application - c#

I'm not authorized to upload error image on stackoverflow. You can see this error image on this link
http://s24.postimg.org/5lduiutqd/error.jpg
I'm creating Facebook menu in window phone 8 on it's showing compile time error.Basically i'm using user control where create a Facebook menu and call it to mainframe.xaml...
User Control Code
<UserControl x:Class="test.UserControls"
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"
xmlns:library="clr-namespace:SlideView.Library;assembly=SlideView.Library"
mc:Ignorable="d"
shell:SystemTray.IsVisible="False"
>
<Grid x:Name="LayoutRoot" Grid.Row="0">
<library:SlideApplicationFrame Header="Test App" Background="White">
<library:SlideApplicationFrame.LeftContent>
<TextBox Name="ss" Width="200"></TextBox>
</library:SlideApplicationFrame.LeftContent>
<library:SlideApplicationFrame.RightContent>
<TextBox Name="sss" Width="200"></TextBox>
</library:SlideApplicationFrame.RightContent>
</library:SlideApplicationFrame>
</Grid>
Mainframe.xaml code
<phone:PhoneApplicationPage
x:Class="test.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"
xmlns:local="clr-namespace:test"
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">
<local:UserControls Name="SSS">
</local:UserControls>
</Grid>
</phone:PhoneApplicationPage>

Related

WPF page content not setting to window's size

I made a WPF application in which. I placed a rectangle. The page is covering whole window but the size(width) of rectangle is not equal to the page.
here is the pic.
here is the source code of my application:
<Page x:Class="TestWpfApplication.Page1"
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:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:TestWpfApplication"
mc:Ignorable="d"
d:DesignHeight="350" d:DesignWidth="525"
Title="Page1" Background="#FF7ACBBC" ShowsNavigationUI="False">
<Grid>
<Rectangle Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="100" Stroke="Black" VerticalAlignment="Top" Width="525"/>
<Label x:Name="label" Content="Heading" HorizontalAlignment="Left" Margin="222.006,25,0,0" VerticalAlignment="Top" FontFamily="Tahoma" FontSize="22"/>
<TextBlock x:Name="textBlock" HorizontalAlignment="Left" Margin="160,155,0,0" TextWrapping="Wrap" Text="And rest of the content goes here" VerticalAlignment="Top" FontFamily="Tahoma" FontSize="14"/>
</Grid>
And
<Window x:Class="TestWpfApplication.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:TestWpfApplication"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<local:Page1/>
</Grid>
At last App.xaml
<Application x:Class="TestWpfApplication.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:TestWpfApplication"
StartupUri="page1.xaml">
<Application.Resources>
</Application.Resources>
Please help me....
Set SizeToContent Property of Window to SizeToContent="WidthAndHeight"
SizeToContent
Page1.Xaml.cs:
public Page1()
{
InitializeComponent();
this.SizeToContent = SizeToContent.WidthAndHeight;
}
For more Info, See Window.SizeToContent Property
I don't know why you specified size parameters for rectangle and expect it to fit your page's size. Just remove all these parameters and it will stretch.
<Rectangle Fill="#FFF4F4F5"/>

Setting child height or width to parent control same as "match_parent" in android

I have a page which includes a grid and within that grid there is a map. But I'm not able to set the size of map same as grid size. Though I can set it in code as
MyMap.Height = LayoutRoot.ActualHeight;
MyMap.Width = LayoutRoot.ActualWidth;
But how can I set it in xaml.
<phone:PhoneApplicationPage
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"
xmlns:maps="clr-namespace:Microsoft.Phone.Maps.Controls;assembly=Microsoft.Phone.Maps"
x:Class="MapSample.MainPage"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<Grid x:Name="LayoutRoot" Background="Red">
<maps:Map x:Name="MyMap" HorizontalAlignment="Left" VerticalAlignment="Top" Center="47.6097, -122.3331" ZoomLevel="10"/>
</Grid>
</phone:PhoneApplicationPage>
You should set the HorizontalAlignment and VerticalAlignmentof the map control to Stretch
<maps:Map x:Name="MyMap"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Center="47.6097, -122.3331"
ZoomLevel="10" />

WPF Image with Remote Path

I am trying to load an image into my Silverlight project and I have the following XAML:
<UserControl x:Class="SilverlightApplication1.MainPage"
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"
d:DesignHeight="300" d:DesignWidth="400" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">
<Grid x:Name="LayoutRoot" Background="White">
<Image Height="150" Width="200" Source="http://wsf.cdyne.com/WeatherWS/Images/rain.gif" />
</Grid>
</UserControl>
The Image control in Silverlight only supports PNG and JPEG, not GIF.
http://msdn.microsoft.com/en-us/library/system.windows.controls.image(VS.95).aspx

Adding portrait child element to landscape page

I'm developing a WP7 app in silverlight. I almost done but, I need to insert new user-control in portrait view as a child element of landscape root page.
Each child element (excluding this) is in landscape mode and it can't be changed.
When I change SupportedOrientation to PortrailorLandscape in RootPage and toggle orientation in emulator to portrait then every child element, that was in landscape, is cutted.
This is what I did:
Page root code:
<phone:PhoneApplicationPage
x:Class="app.Root"
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"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Landscape" Orientation="LandscapeLeft"
mc:Ignorable="d" d:DesignHeight="480" d:DesignWidth="800" shell:SystemTray.IsVisible="False">
<Grid Width="800" Height="480" Loaded="RootGrid_Loaded">
<Popup x:Name="myPopup">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="480"/>
</Grid.RowDefinitions>
<Border x:Name="popupBorder"/>
</Grid>
</Popup>
<Canvas x:Name="ScreenRoot"
Visibility="Visible"
Width="800" Height="480">
<Canvas.Children/>
</Canvas>
</Grid>
</phone:PhoneApplicationPage>
Then user-control as a child of ScreenRoot:
<UserControl
x:Class="app.Settings"
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"
FontFamily="{StaticResource OCRAExt}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="WhiteSmoke"
mc:Ignorable="d" d:DesignHeight="800" d:DesignWidth="480"
shell:SystemTray.IsVisible="False">
<Grid x:Name="SettingsRoot" Background="Black" Width="480" Height="800">
...
...
</Grid>
</UserControl>
User control listens his state in state machine and then add itself as a Child to Canvas of RootPage.
Please help me:)
I'm not sure to understand what you really want to do, but you can try to apply a RenderTransform to your UserControl, in order to keep it in portrait mode.
http://msdn.microsoft.com/en-us/library/ms754009.aspx

Windows Phone WebBrowser Control Not Rotating, Height Not 100%

I'm building my first simple Windows Phone app. I'm having some trouble though.
I'm using a WebBrowser control to show a web page that I don't have control over. For some reason, the control doesn't rotate with the phone. I'm completely at a loss as to why.
I can't get the height to be 100% of the phone. If I set it to auto, I think it's getting executed as 0.
Can anyone help me with this?
Here's the XAML for a very simple app that only contains a WebBrowser control. It is full size and rotates. Can you compare with your app and spot what's different? BTW, the only attribute I changed on the elements was the value of #SupportedOrientations.
<phone:PhoneApplicationPage
x:Class="WP7WebBrowser.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"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="PortraitOrLandscape" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<Grid x:Name="LayoutRoot" Background="Transparent">
<phone:WebBrowser Source="http://www.bing.com"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" />
</Grid>
</phone:PhoneApplicationPage>
Hope that puts you on the right path!

Categories

Resources