Why won't my Silverlight PivotViewer load? - asp.net

I have a PivotViewer app I am working on, but, I cannot get it to run.
I have a good .cxml file (I used Pauthor to generate the related deep-zoom files). I have tried running it from inside VS 2010 int debug and even built it and tried running it from my localhost. I've checked it in both Firefox and IE. I've made sure it is in a container with set width and height. I've made sure I have the most current silverlight.js, I've set the appropriate MIMEs on IIS.
My XAML:
<UserControl x:Class="DomPivot.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"
xmlns:pivot="clr-namespace:System.Windows.Pivot;assembly=System.Windows.Pivot"
mc:Ignorable="d"
d:DesignHeight="400" d:DesignWidth="400" Loaded="UserControl_Loaded">
<Grid x:Name="LayoutRoot" Background="White" Width="400" Height="400">
<pivot:PivotViewer x:Name="myPivot" Height="350"></pivot:PivotViewer>
</Grid>
</UserControl>
My error:
Error: Unhandled Error in Silverlight Application Set property 'System.Windows.FrameworkElement.Style' threw an exception. [Line: 11 Position: 52]
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
at DominionPivot.MainPage.InitializeComponent()
at DominionPivot.MainPage..ctor()
at DominionPivot.App.Application_Startup(Object sender, StartupEventArgs e)
at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)
Source File: DomPivotTestPage.aspx
Line: 0
Line 11 Position 52 of the main.xaml is now the equal sign for the Height property of the pivotviewer. Interesting that BEFORE I added the height property, the project threw this error at the equal sign for the x:Name property.
I don't understand why I'm getting this error and would appreciate some help. I've investigated the other topics here but none of those answers either worked or pertained to my situation.
UPDATE:
I've attempted to make sure it isn't some kind of other error cascading into an inability for the control to load by attempting to load a .CXML file from a public source. Same result. I don't think the control itself is loading, so, I can't even debug the code that loads the collection.
Googling "Unhandled Error in Silverlight Application Set property 'System.Windows.FrameworkElement.Style' threw an exception." is no help. It returns 24 hits. Half of those are unrelated. The other half is another person with what appears to be the same problem posting to half-dozen or more forums and getting no answer either.

OK....so here are a number of issues that a lot of frustrating googling and futzing revealed:
Loaded="UserControl_Loaded"
I'm not entirely sure how this parameter ended up in my UserControl tag, but, it is unnecessary and eliminated the error referenced in my question.
I also moved the LoadCollection method out of its own event and into the UserControl_Loaded event and got things to progress.
Next I found that if you are using Visual Studio to run the project, make sure you specify the port number both in your code and in your web project settings. These obviously need to be changed when you post to a live server.
Lastly, I was led to believe that you HAD to use either the freely available Pauthor tools or the Excel plug-in to transform your collection into a Deep Zoom. Which also requires futzing with IIS to allow .dzi and .dzc.
Not so. There is a freely available Microsoft Deep Zoom Composer tool. In that tool you can compose your deep zoom and export the collection. You'll end up with several xml files and image folders. I found that all you have to do is then reference the output_dzc.xml file in your collection.cxml as your ImgBase and make sure your IDs match between the two files. That's all.
I hope this saves someone the frustration I've experienced the last few weeks trying to use this awesome but pathetically under-documented control.
I would also recommend this blog entry:
http://indiandotnet.wordpress.com/2011/02/12/pivot-viewer-example-cricket-world-cup-2011/
It contains a link to a very simple pivotviewer VS 2010 solution file you can use to examine and familiarize yourself with file and directory structure as well as the necessary XML file structure and solution settings.

Related

Windows forms designer NullReferenceException- where to go from here?

When I try to open one of my forms in the designer, it says, "Object reference not set to an instance of an object." It does not provide a way to continue, and it does not give me any clue as to what is causing the error.
at Microsoft.VisualStudio.Design.Serialization.CodeDom.MergedCodeDomParser.System.CodeDom.Compiler.ICodeParser.Parse(TextReader stream)
at System.CodeDom.Compiler.CodeDomProvider.Parse(TextReader codeStream)
at Microsoft.VisualStudio.Shell.Design.Serialization.CodeDom.CodeDomDocDataAdapter.get_CompileUnit()
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
at System.ComponentModel.Design.Serialization.BasicDesignerLoader.BeginLoad(IDesignerLoaderHost host)
The code compiles and runs perfectly. Cleaning, rebuilding, closing, reopening haven't worked. All the other forms open fine.
I don't even know what information is relevant. What recourse do I have to debug this?
This will sound silly. The form is apparently a duplicate for a work in progress and the build action was set to None. Setting it to Compile caused the designer to act as normal.
It would be nice if the designer would at least point you in the right direction. Problem solved.
This is because there is' an exception in the event "Load" of the form.
Place the code inside a "try .. catch" block to see the exception

Does mate framework for flex leak with injectors?

I have been trying to pinpoint a memory leak I have in my flex application and I have just discovered that it might be related to mate.
I'm using mate's Injectors (in a mapping file) to inject an item to a popup:
<Injectors target="{MyTitleWindow}">
<PropertyInjector targetKey="item" source="{MyManager}" sourceKey="item" />
</Injectors>
I'm then using PopUpManager.addPopup and PopUpManager.removePopup to show/remove the popup but when I profile my application, I see that the count of MyTitleWindow objects only incline (removePopup does not free up the memory)
When I remove the injectors, everything works well ...
Has anyone encountered that issue? I guess I can override this issue by not using the injectors but I do hope there's a simpler solution ...
Edit
I've just learned that starting from version 0.8.8, PropertyInjector includes a property called softBinding which should (as I understand) fix this issue, but it doesn't ...

Resource can't be found even when it's present

I've got a really weird issue I can't fix within a Wpf Application. We built a Common Library containing many useful components, one of them is a fancy MessageBox which has the company style. There're three dictionaries that contains nearly everything we require:
<ResourceDictionary Source="/Library;component/Style/Styles.xaml" />
<ResourceDictionary Source="/Library;component/Themes/Globals.xaml"/>
<ResourceDictionary Source="/Library;component/Themes/Controls/Button/Template.xaml"/>
There's a footer for the MessageBox into Globals.xaml, footer uses a template from Template.xaml. It works perfectly but not in one case. I have a main window that dinamically create a plugin and open a window. This window is a regular Window Wpf application loaded through reflection.
Method to open MessageBox is within the same DLL as Resource Dictionaries.
If I call this MessageBox method from the plugin it throws an exception because "Footer" is not found. I set a breakpoint before
window.ShowDialog();
And I see MergedDictionaries is empty into window. Also empty everywhere, only owner of this MessageBox contains those resources. Doing
window.FindResource("key");
Get a null value as expected. However, if I manually copy merged dictionaries using this code lines before open dialog:
foreach (var dict in owner.Resources.MergedDictionaries)
{
window.Resources.MergedDictionaries.Add(dict);
}
And then look for window.FindResource("key") I can see the style, but even though it continues throwing an exception:
Cannot find resource named '{Footer}'. Resource names are case sensitive.
Footer style is used in this line of MessageBox:
<StatusBar Style="{StaticResource Footer}" DataContext="{Binding ElementName=window}"...
I've also tried to declare this resource into the DialogWindow in the library, even when I've not gonna be allowed to change it:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Library;component/Themes/Generic.xaml" />
<ResourceDictionary Source="/Library;component/Themes/Globals.xaml"/>
<ResourceDictionary Source="/Library;component/Themes/Controls/Button/Template.xaml"/>
</ResourceDictionary.MergedDictionaries>
I've been 2 days knocking my head on the monitor and nothing, everything I tried failed. Despite of breaking a monitor of course.
Ran out of ideas...
Regards.
Make sure of the following things
The resource dictionary Build Action is set to Page
Every project that references the Style has a library reference to it (Even if you put the Dictionary in App.xaml if a project that doesn't reference the Resources Library then it wont find it
Place the MergedDictionaries in App.xaml (or in the specific page you want to use them)

MVVM Light + Blend designer view error: Cannot find resource named 'Locator'.

The application runs fine but i could not see my design in the designer view.
It says Cannot find resource named 'Locator'. Obviously, i did not change anything in the code, i just did the data binding using the data binding dialog...
anyone facing the same problem?
There are two known occurrences where this can happen.
If you change to Blend before you built the application, the DLLs are not available yet and this error can be seen. Building the application solves the issue.
There is a bug in Expression Blend where, if you are placing a user control in another user control (or Window in WPF), and the inner user control uses a global resource, the global resource cannot be found. In that case you will get the error too.
Unfortunately I do not have a workaround for the second point, as it is a Blend bug. I hope we will see a resolution for that soon, but it seems to be still there in Blend 4.
What you can do is
Ignore the error when working on the outer user control. When you work on the inner user control, you should see the design time data fine (not very satisfying I know).
Use the d:DataContext to set the design time data context in Blend temporarily.
Hopefully this helps,
Laurent
I've come up with a reasonably acceptable workaround to this problem since it doesn't appear to have been fixed in Blend 4:
In the constructor for your XAML UserControl just add the resources it needs, provided you're in design mode within Blend. This may be just the Locator, or also Styles and Converters as appropriate.
public partial class OrdersControl : UserControl
{
public OrdersControl()
{
// MUST do this BEFORE InitializeComponent()
if (DesignerProperties.GetIsInDesignMode(this))
{
if (AppDomain.CurrentDomain.BaseDirectory.Contains("Blend 4"))
{
// load styles resources
ResourceDictionary rd = new ResourceDictionary();
rd.Source = new Uri(System.IO.Path.Combine(Environment.CurrentDirectory, "Resources/Styles.xaml"), UriKind.Absolute);
Resources.MergedDictionaries.Add(rd);
// load any other resources this control needs such as Converters
Resources.Add("booleanNOTConverter", new BooleanNOTConverter());
}
}
// initialize component
this.InitializeComponent();
}
There may be some edge cases, but its working OK for me in the simple cases where before I'd get a big red error symbol. I'd LOVE to see suggestions on how to better solve this problem, but this at least allows me to animate user controls that otherwise are appearing as errors.
You could also extract out the creation of resources to App.xaml.cs:
internal static void CreateStaticResourcesForDesigner(Control element)
{
if (AppDomain.CurrentDomain.BaseDirectory.Contains("Blend 4"))
{
// load styles resources
ResourceDictionary rd = new ResourceDictionary();
rd.Source = new Uri(System.IO.Path.Combine(Environment.CurrentDirectory, "Resources/Styles.xaml"), UriKind.Absolute);
element.Resources.MergedDictionaries.Add(rd);
// load any other resources this control needs
element.Resources.Add("booleanNOTConverter", new BooleanNOTConverter());
}
}
and then in the control do this BEFORE InitializeComponent():
// create local resources
if (DesignerProperties.GetIsInDesignMode(this))
{
App.CreateStaticResourcesForDesigner(this);
}
Note: At some point in time this stopped working for me and I ended up hardcoding the path to the Styles.xaml because I got frustrated trying to figure out which directory I was in.
rd.Source = new Uri(#"R:\TFS-PROJECTS\ProjectWPF\Resources\Styles.xaml", UriKind.Absolute);
I'm sure I could find the right path with 5 minutes work, but try this if you're at your wits end like I was!
In MyUserControl.xaml, instead of:
DataContext="{Binding Main, Source={StaticResource Locator}
use:
d:DataContext="{Binding Main, Source={StaticResource Locator}
where "d" has been previously defined as:
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
The reason and workaround explained here
http://blogs.msdn.com/b/unnir/archive/2009/03/31/blend-wpf-and-resource-references.aspx
Look at (b) part of the post.
I had a similar problem with a user control resource.
I added this in my usercontrol xaml code:
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/GinaControls;component/Resources/GinaControlsColors.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
Where GinaControls is the namespace where the control class is declared and /Resources/GinaControlsColors.xaml is the project folder and xaml resource file name.
Hope this helps.
Just add this in your App.xaml.cs at the very beginning
here's my piece of code
[STATThread()]
static void main(){
App.Current.Resources.Add("Locator", new yournamespace.ViewModel.ViewModelLocator());
}
public App(){
main();
}
Make sure the Blend has opened the entire solution and NOT just the single project containing the views. I was right-clicking in Visual Studio and selecting Open In Expression Blend. To my surprize, Blend could not find the solution file, so it only opened the single project.
When I realized this, I launched Blend directly, pointed it to the solution file, and then Blend was able to find the ViewModelLocator in my view.

IOErrorEvent Eluding Capture

I'm working on a Flex application that processes and displays small amounts of HTML, sometimes including images. I'm getting the HTML out of third-party RSS feeds. Sometimes, I see this in a pop-up window:
Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.
The RSS URL is just fine, but there's apparently something in the downloaded HTML that's causing a problem. Since the application is meant to run as part of a non-interactive digital sign, anything that requires a click to continue is completely unacceptable. I don't care how useless or malformed a URL is; the app needs to ignore the problem without pestering the user.
Unfortunately, I'm having no luck trapping this event. I'm sprinkling calls like this liberally through the code:
[object].addEventListener(IOErrorEvent.IO_ERROR, handleIOError);
... where [object] is everything from the mx:Text object rendering the HTML to its mx:Canvas parent to the mx:Application top-level app, and handleIOError is a simple function that looks like this:
private function handleIOError(event:IOErrorEvent):void {
trace ("IO error occurred: " + event);
}
But so far, nothing; that bloody error keeps popping up in the Flash player. Does anybody have any insight as to where I'm going wrong?
Make sure you are putting the event on the right object. I haven't done a whole lot of remote loading in Flex, but in Flash, a hilarious and annoying quirk is that when you use the Loader class to load images, the object you need to put event handlers on is NOT the Loader itself, but a property of the loader called contentLoaderInfo.
Read the docs carefully on the objects you are using, a similar pitfall might be at play.
IOErrorEvent is not bubbled so you cant catch or control it if someone else is implementing it.
Please find out which third party component you are using and try to get source if its open source or read some documentation or ask support guys on how to turn off this alert.
For example, if I made RSS component for flex and on error if I displayed the alert, if you use my component, whatever you can do you cant turn off my error alert unless i have provided you a boolean switch to turn it off. So this is really a problem with who has written the code for this alert box. Whatever you do you will not be able to turn this thing off. Except reverse engineer, change the code and recompile it, but it should be legal.

Resources