Since the xaml window stopped showing my wpf form using VS 2012 (after I added some comments to the top of the main .cs form), I reverted back to C# Express 2010.
I copied my xaml and code and pasted them into the new project.
However, I’m getting err msgs such as:
*’duckbilledPlatypusInfoMailer_Express.MainWindow’ does not contain a definition for ‘MainWindow_Loaded’ and no extension method ‘MainWindow_Loaded’ accepting a first argument of type ‘duckbilledPlatypusInfoMailer_Express.MainWindow’ could be found (are you missing a using directive or an assembly reference?)*
and:
The name ‘InitializeComponent’ does not exist in the current context
I get the same err msg about two controls, my label and button (but not the DatePicker!)
So both of my event handlers, and two of my three controls, as well as the ‘InitializeComponent’ have been rendered in a cloak of invisibility, as far as VC#2010 is concerned…???
Here is my xaml and code (minimal, so p[a,o]sting all of it):
XAML:
<Window x:Class="duckbilledPlatypusInfoMailer_Express.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Duckbilled Platypus Info Mailer" SizeToContent="WidthAndHeight" WindowStartupLocation="CenterScreen" MinHeight="350" MinWidth="525" Loaded="MainWindow_Loaded" >
<StackPanel>
<StackPanel Orientation="Horizontal">
<Button x:Name="btnSelectPDFFile" HorizontalAlignment="Left" Padding="4" Margin="4" Width="120" Click="btnSelectPDFFile_Click" IsDefault="True">Select PDF File
</Button>
<Label x:Name="lblPlatypusSheetFile" Margin="4" >[Selected File]</Label>
</StackPanel>
<StackPanel Orientation="Horizontal">
<DatePicker ></DatePicker>
</StackPanel>
</StackPanel>
</Window>
CODE:
using System;
using System.Windows;
using duckbilledPlatypusInfoMailer;
namespace PlatypusInfo_Express
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
btnSelectPDFFile.Focus();
}
private void btnSelectPDFFile_Click(object sender, RoutedEventArgs e)
{
var dlg = new Microsoft.Win32.OpenFileDialog
{
InitialDirectory = @"C:\Scrooge\McDuckbilledPlatypus\",
DefaultExt = ".pdf",
Filter = "Platypus Data Sheets (sa*.pdf)|sa*.pdf"
};
bool? result = dlg.ShowDialog();
if (result == true)
{
string pdfFilename = dlg.FileName;
// Show just the file name, without the path
string pdfFileNameOnly = System.IO.Path.GetFileName(pdfFilename);
lblReviewSheetFile.Content = pdfFileNameOnly;
string textFilename = String.Format(@"C:\Scrooge\McDuckbilledPlatypus\{0}.txt", pdfFileNameOnly);
var pdfParser = new PDFParser();
if (pdfParser.ExtractText(pdfFilename, textFilename))
{
System.Diagnostics.Process.Start(textFilename);
}
else
{
MessageBox.Show("There was a boo-boo, Yogi!");
}
}
}
}
}
BTW, I did add the necessary 3rd party file to my solution (PDFParser.cs) as well as the two necessary references.
Note: If I right-click the event handlers in the xaml, it DOES take me to those event handlers in the cs file. So it knows where they are, why does it say they don’t exist or it can’t find them?
UPDATE
Here’s the first part of the error I see in the WPF designer:
System.NotSupportedException
An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information.
at Microsoft.Expression.DesignHost.Isolation.Remoting.STAMarshaler.WaitForCompletion(NestedCallContext nestedCallContext, BlockingCall call, WaitHandle timeoutSignal)
at Microsoft.Expression.DesignHost.Isolation.Remoting.STAMarshaler.MarshalOut(Action action, Int32 targetApartmentId, WaitHandle aborted, WaitHandle timeoutSignal)
at Microsoft.Expression.DesignHost.Isolation.Remoting.ThreadMarshaler.MarshalOut[TValue](RemoteHandle1 targetObject, Action action)1 targetObject, Func`2 func)
at Microsoft.Expression.DesignHost.Isolation.Remoting.ThreadMarshaler.MarshalOut[TResult,TValue](RemoteHandle
There is an extra
duckbilledin the namespace in the XAML :it has to be in the same namespace as to code behind class.