InitializeComponent not defined after converting from Windows phone 8 silverlight to universal apps - silverlight

I have a Windows phone 8 Silverlight App that I'm trying to convert to Windows Universal Apps. I used a free tool from this website http://www.mobilize.net/silverlight which helps with the transition but I've encountered a weird error.
I've already searched through other posts and everyone seem to get this to work.. but those solutions aren't working for me... let me explain.
I have lots of Pages in my project and they all show the same error, different from the App.xaml.cs page.
In App.xaml.cs
In Main.xaml.cs
This is a link to another post with some solutions BlankPage constructor cannot initialize components
Now I checked my App.xaml and MainPage.xaml and they are correct according to the solution for everyone elese.
This is App.xaml first line:
<Application x:Class="StayMobileWP81.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="using:System" xmlns:local="using:StayMobileWP81">
And this is MainPage.xaml first line:
<Page x:Class="StayMobileWP81.Main" 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" p2:SystemTray.BackgroundColor="#AF252B" p2:SystemTray.ForegroundColor="White" xmlns:p1="using:Microsoft.Phone.Shell" xmlns:p2="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone">
Both .cs files I use namespace StayMobileWP81.
Still having this error... And I tried to change Entrypoint in the Package.appxmanifest to point to "StayMobileWP81.App" and still nothing... It's currently pointing to Main.xaml
I also saw in another post that I had to change Build Action property to Page for InitializeComponet to work but, in my case, they were already set to Page in Main.xaml and ApplicationDefinition in App.xaml.
Does anyone know what am I missing here?

Related

Draw on top of Windows Forms control

For my current project, I am required to display a PDF, and then draw on top of it. I am using Adobe Reader as a PDF viewer, as this can be hosted in a Windows Forms control which can in turn be hosted in a WPF application. However, I cannot draw over this control.
There seem to be a couple of approaches to solving this problem out there, but for the life of me I cannot seem to find a good example of a generic solution that would fit into my existing code. The most common solution I can see are Adorner/Layer/Decorators, but I can't find a way to get them into my XAML in a way that won't break the application.
My current XAML is as follows:
<Window x:Class="ThisProject.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ThisProject"
Title="MainWindow" Height="768" Width="1366"
WindowState="Maximized" WindowStyle="None" KeyDown="WindowKeyDown"
Loaded="WindowLoaded">
<Grid Name="PDFGrid">
<local:PDFViewerHost x:Name="PdfViewer"/>
</Grid>
</Window>
What I will need to go on top of the PDF viewer is a bunch of shapes, defined at runtime. Any suggestions as to a method that will allow me to stick those shapes on top of it would be greatly appreciated.
Thanks!

My WPF Application cannot locate resource 'Mainwindow.xaml'

I have been working on a WPF application using vb.net and I've recently run into a problem.
When I build my code, the build is successful but when it comes to running the code the System.IO.IOexception throws an exception "Cannot locate resource ViewModel/ViewModel/Mainwindow.xaml"
The .Xaml windows are located in a folder called ViewModel hence I don't know where the other ViewModel/ViewModel... path is coming from, isn't it supposed to be viewModel/MainWindow.Xaml?
I have tried all possible solutions including cleaning up the Project but it doesn't seem to work.
The only solution that seems to work is if I change the StartupUri from
StartupUri = "ViewModel\MainWindow.Xaml" TO StartupUri = "...\MainWindow.xaml" but I doubt if that is the right thing to do.
Change the StartupUri="MainWindow.xaml" to StartupUri="FolderName/MainWindow.xaml"
Solved my problem, when I moved my MainWindow to the View Folder
In my case I needed to use pack URI syntax to set SrartUpUri property of my App.xaml file to point to a new location of my MainWindow.xaml, as so:
<Application x:Class="TrafficLights.Controller.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="pack://application:,,,/View/MainWindow.xaml">
More on pack URIs here:
http://msdn.microsoft.com/en-us/library/aa970069(v=vs.110).aspx
Hope it helps. Good luck!
This happened to me few times - always when I moved MainWindow.xaml to different folder and forgot to update StartupUri in App.xaml.
Visual Studio has somehow renamed my MainWindow.xaml to MainWindow(1).xaml, so again I renamed it to MainWindow.xaml
I renamed the Mainwindow.xaml file to NameList.xaml and had not updated the App.xaml file. Once I did that StartupUri="NameList.xaml", it was fine.

WPF merged resource dictionaries in every user control - bad idea?

I keep my app's resources in a separate DLL and reference them in my main EXE using something like this in App.xaml:-
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MyThemesAssembly;component/Themes/Generic.xaml"/>
</ResourceDictionary.MergedDictionaries>
When I edit a window that's in the main EXE project, the VS2010 designer doesn't recognise any resources from the other assembly, so I don't see any styling applied (not really an issue as I always work in the XAML view). However Resharper doesn't recognise these external resource names either, resulting in lots of squiggles under resource names when I'm editing XAML.
I've found that I can fix both the VS designer and Resharper by including the above XAML in each window and user control, but is this going to have an adverse effect on memory and/or performance? Will each window get a separate copy of the resources?
We had a problem in our application with the use of ResourceDictionaries referenced in each UserControl / View. I advise against that. We managed to reduce our application's memory footprint by like 300 mb by the use of SharedResourceDictionaries. I looks like you will end up with the ResourceDictionary being instantiated once for every single UserControl in your application. Don't do that just to fix VS designer.
Try using VS2012.
I have a test project which I was using which I was doing resource dictionary merging from an external assembly and in my app.xaml I have this:
<Application x:Class="WpfPackDictionaries.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/WPFCommonLibrary;component/Vectors/Vectors.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
Then in my mainwindow.xaml I have this where the path pulls in a style ModifiablePathStyle:
<Window xmlns:Control="clr-namespace:WPF.Common.Control;assembly=WPFCommonLibrary" x:Class="WpfPackDictionaries.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Path Style="{StaticResource ModifiablePathStyle}" Fill="Red"/>
<Control:Jabberwocky />
</Grid>
</Window>
Intellisense/Resharper (V7.1 10/31 (Early Access Build)) recognizes the style and I have no squigglies:
Hence have you tried to work in VS2012?
VS2012 is able to 'see' resources since VS XAML designer loads and executes your code in design-time, so VS can inspect what resources will be available at runtime. ReSharper never uses design-time code execution (since this requires your code always be in compilable state) so XAML support became a bit more complex task.
ReSharper 8.0 implemented support for BAML decompilation and do extracts the list of XAML files and resolves XAML resources from referenced binary assemblies.

Exception when using silverlight toolkit 5 controls

I'm working an application that is based on Silverlight 5.
It's framework is MVVM and implemented by Prism.
I'm using silverlight 5 toolkit too.
In one of my views I using wrapPanel and DateTimePicker from toolkit.
<navigation:Page x:Class="PIPM2.SupervisionSubSystem.Module.View.TestView"
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"
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
d:DesignWidth="640" d:DesignHeight="480"
Title="TestView Page" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit" xmlns:my="clr-namespace:Silverlight.Controls;assembly=Silverlight.Controls" xmlns:my1="clr-namespace:Silverlight.Controls.Primitives;assembly=Silverlight.Controls">
<Grid>
<sdk:DatePicker />
<toolkit:WrapPanel >
</toolkit:WrapPanel>
</Grid>
</navigation:Page>
This sample buid successed but at runtime in InitializeComponent() method I got this Error =>
Could not load file or assembly 'System.Windows.Controls.Toolkit, Version=5.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The requested assembly version conflicts with what is already bound in the app domain or specified in the manifest. (Exception from HRESULT: 0x80131053)
If I delete one of controls, wrapPanel or DatePicker the Error do not occur again.
How can I solve this problem.
What exact version of System.Windows.Controls.Toolkit are you currently referencing? Do you have multiple projects? If so, do different projects reference different versions of that same assembly?
If you want to know for sure which version of the DLL you are getting, just go to your .XAP file and rename it to .ZIP (XAP files are really ZIP files). Now look in the ZIP file and see exactly which DLL you have and what the version number is.

Extended WPF Toolkit - using the RichTextBoxFormatBar

I've been trying to use the Extended WPF Toolkit so that I can make use of the RichTextBoxFormatBar but I seem to be going round in cirlces. Despite trying several examples on here and other sites I keep getting the same error messages:
The attachable property 'FormatBar' was not found in type 'RichTextBoxFormatBarManager'.
The type 'toolkit:RichTextBoxFormatBar' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.
I'm new to WPF so I'm know it's something I'm not picking up on rather than a bug, can anyone tell me what I'm doing wrong and save my sanity?
<UserControl x:Class="TestWPF_Richtextbox.UserControl1"
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:toolkit="http://schemas.xceed.com/wpf/xaml/toolkit"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<RichTextBox>
<toolkit:RichTextBoxFormatBarManager.FormatBar>
<toolkit:RichTextBoxFormatBar />
</toolkit:RichTextBoxFormatBarManager.FormatBar>
</RichTextBox>
</Grid>
</UserControl>
EDIT: Both the library and the project are .Net 4. The version of the WPFToolkit.Extended.dll is V.1.6.0.0.
My own stupid fault.
I'd forgotten to unblock the DLL when I downloaded it as per the instructions which say that after downloading the ExtendedWPFToolkit_Binaries.zip you should then right click on it, select "Properties" and then "Unblock".
Hopefully this post will help someone else who has made the same mistake.
I'm hardly a rookie - but had the same issue.
Frankly I've never heard of unblocking a .zip file. Like most people I just skimmed the instructions, after all I know how unzip a file - or so I thought.
I had fought with extended toolkit 1.9.0 for two hours because my app would compile, run and work, but VS12 designer couldn't render the window. THen I saw the above post about unblocking the zip before expanding. Thought to myself "whiskey tango foxtrot" is this guy talking about. But I was desperate, so I closed VS. Deleted my expanded files. This time did the unblock. THen expanded into the very same locations. Restarted Visual Studio and to my amazement the designer now renders the controls and don't complain about the WatermarkTextBox not being in the namespace etc.
Really a humbling experience about reading the directions more closely.
This same thing happened to me and I eventually figured out it was either because I had the dll or the solution stored on the network instead of my local computer. I moved both to the local computer and it started working.

Resources