Silverlight Won't Load PivotViewer Collection - silverlight

I'm trying to get a proof-of-concept PivotViewer application up and running, but I can't get the collection to load properly, even in a testing environment. I'm following these instructions:
Building Your First PivotViewer Application
I have a clientaccesspolicy XML file in the root, giving all URIs access. I copied an already existing collection, and have it in the root as well. The collection XML checks out properly.
Whenever I attempt to debug the application, however, it loads but simply displays the URL for the collection, never actually building the PivotViewer.
MainPage.xaml:
<UserControl x:Class="PivotViewer.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="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="White">
<Pivot:PivotViewer x:Name="Pivot" />
</Grid>
</UserControl>
MainPage.xaml.cs:
namespace PivotViewer
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
Pivot.LoadCollection("http://localhost:55334/Top_Movies.cxml", string.Empty);
}
}
}

OK, here's a number of ways forward for you.
Firstly, wire up the PivotViewer's CollectionLoadingFailed event before calling the LoadCollection method. This will expose a CollectionErrorEventArgs containing any exceptions.
Secondly, install Fiddler2 and use it to watch what the PivotViewer is requesting. If it's failing to reach certain parts of the pivot collection it will be very obvious.
Let me know what those 2 suggestion bring to light.

Related

Left-click doesn't work on web canvas being hosted in WPF WebBrowser

I'm trying to present vis.js web page in my WPF using WebBrowser, the page presented successfully but I can left-click any of the items inside the canvas.
Mouse zoom is working as expected inside the canvas.
I wrote a simple project contains only 2 files:
MainWindow.xaml:
<Window x:Class="WpfApplication1.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>
<WebBrowser x:Name="webBrowser"></WebBrowser>
</Grid>
</Window>
MainWindow.xaml.cs:
using System.Windows;
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
webBrowser.Navigate("http://visjs.org/examples/network/other/configuration.html");
}
}
}
Note: I added my registry the following key so my WPF process will use IE11:
Key name: HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Internet
Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION\processName.exe
Type: REG_DWORD Value Data: 11000 (decimal)
I won't answer your question directly but I'll give you some advice based on my experience, and that is: never use default wpf WebBrowser for anything even remotely serious. I tried to use it before many times for many different projects and always got some showstopper issue, no exceptions. And of course that is with IE11 (10,9 - I tried it many times as I said) emulation.
Look at your case for example. Not only canvas clicks do not work - whole page is completely destroyed. Sliders are messed up, if you try to choose a color - clicks again do not work, and many more issues on this single page.
So, don't bother with wpf WebBrowser and just use real browser, for example Chromium. I personally prefer CefSharp which has wpf binding to chromium. Just install their nuget package (CefSharp.WPF), then:
<Window x:Class="WpfApplication2.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:wpf="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<wpf:ChromiumWebBrowser x:Name="webBrowser"/>
</Grid>
</Window>
And
InitializeComponent();
webBrowser.Address = "http://visjs.org/examples/network/other/configuration.html";
And you page just displays as it should. Canvas clicks work, no styles are destoyed, color pickers work. In addition to all that, cefsharp browser control is much more flexible. You can call to\from javascript easily, intercept almost every event (resource load, redirections), you can disable javascript\images, even intercept requests and feed completely different data. And no need to fix registry on every client machine.
Note that if you would install CefSharp.WPF via package, it will require your project to have x86\x64 platform (does not work with AnyCPU). But you really can make it work with anyCPU with little effort, if you would have such requirement.

Why does ServiceLocator.Current.GetInstance cause UserControls to not work at design-time?

I'm having an issue where if I call ServiceLocator.Current.GetInstance(type) anywhere in my project, it causes UserControls throughout my project to stop instantiating within other controls at design-time in Visual Studio. These controls work fine at run-time however.
It is reproducible by creating a simple WpfApplication with the following 3 classes. The first build will succeed, and the designer will show fine. If you rebuild, however, it throws the error and the designer stops instantiating the UserControls within other controls. Because of this behavior, it seems like a Visual Studio bug, but I'm not sure.
When uncommented, the #GetInstance(Type type) function of ServiceLocator causes an Error in the error list Cannot locate resource 'controls/test.xaml and the designer shows an error Cannot create an instance of "Test" where the Test UserControl should be. When commented, there are no errors.
Test xaml class.
<UserControl x:Class="XamlTest.Controls.Test"
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"
mc:Ignorable="d">
<Grid>
<Label Content="Test"/>
</Grid>
</UserControl>
MyView xaml class. (uses Test)
<UserControl x:Class="XamlTest.Views.MyView"
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:mycontrols="clr-namespace:XamlTest.Controls"
mc:Ignorable="d">
<Grid>
<mycontrols:Test/>
</Grid>
</UserControl>
A class unrelated to the UserControls that uses ServiceLocator.Current.GetInstance(type);.
using Microsoft.Practices.ServiceLocation;
namespace XamlTest.SomeClasses
{
class SomeClass
{
public void SomeFunction()
{
// Causes Test xaml class to not instantiate at design time within MyView.
// Does not matter what parameters you give the function.
// Notice this class isn't even associated with any other class,
// and is never called, but it still causes problems.
ServiceLocator.Current.GetInstance(null);
}
}
}

windowsformhost cant load a usercontrol from another dll

So I have a dll from another project which contains many useful classes and controls for me (lets call it foo.dll). I'm making an WPF app. I need to use some of them in my app. I created my usercontrol for windows forms and referenced UserControlForMe from foo.dll. It's shown, all good. Now I want to insert my usercontrol into a wpf form. It looks like this:
<UserControl x:Class="FlatRectangular_Profile.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"
mc:Ignorable="d"
xmlns:uc="clr-namespace:FlatRectangular_Profile.UC"
Height="2093" Width="717">
<Grid Name="grid">
<WindowsFormsHost>
<uc:WindowsFormsProfManual ></uc:WindowsFormsProfManual>
</WindowsFormsHost>
</Grid>
</UserControl>
But here I get an error "cant load type UserControlForMe from foo.dll". No info on that error. Again, UserControlForMe loads in WindowsFormsProfManual. All these is going on in one class library. I referenced everything that foo.dll needed.
No idea how what to do next. I also tried to load it in code in usercontrol.loaded event, but it fails too, and shows stacktrace which leads to the constructor of the UserControlForMe.
I guess you'll have to add the assembly to your namespace import to point your application in the right direction:
xmlns:uc="clr-namespace:FlatRectangular_Profile.UC;Assembly=MyDLL"
I found a workaround since I cant get why it is not working. If I load a UserControlForMe from foo.dll directly to the windowsformhost, it works. But if there is a "buffer" dll, it works in this dll, but doesnt open in futher window. Also I add a UserControlForMe programmatically to a windowsformhost.

XAML.Parse.Exception on WPF project's deployment

I'm having a problem when I deploy my WPF project, the deployed project crashes on startup and produces a XAML.Parse.Exception with an inner exception of "Cannot have nested BeginInit calls on the same instance" at Line 4 Position 70. The App has full permissions on my computer. I am asking this question because the few questions asked about this had no real solution to the problem.
Here is the XAML code it is referencing with the first couple of lines.
<Window
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" x:Class="ASRV.MainWindow"
Title="ASRV GUI" Height="768" Width="1024" ResizeMode="CanMinimize">
<Window.Resources>
</Window.Resources>
<Window.Background>
<ImageBrush ImageSource="pack://siteoforigin:,,,/background.png"/>
</Window.Background>
My guess is the reason being:
<Window.Background>
<ImageBrush ImageSource="pack://siteoforigin:,,,/background.png"/>
</Window.Background>
You might be reusing this image elsewhere in the same window or subcontrol.
BeginInit is called in databinding and this is the only databound thing I could see in your sample code. "BeginInit calls on the same instance" points to it being bound twice.
This error is encountered whenever an object is attempted to be bound twice, as #basarat says in his answer. Further to the example seen in the OP, I came across this same error caused in my case by setting a DataContext in the CodeBehind as well as in the xaml:
In the MainWindow.xaml file, I had the following:
<Window xmlns:vm="clr-namespace:MyApp.ViewModel"
[...more xmlns references skipped for brevity...]
<!--the next three lines caused a problem, when combined with the code behind-->
<Window.DataContext>
<vm:MainViewModel/>
</Window.DataContext>
</Window>
And in the MainWindow.xaml.cs file, I had this:
namespace MyApp.View
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainViewModel MainViewModel { get; set; }
public MainWindow()
{
bool success = false;
MainViewModel = new MainViewModel();
// This line caused the problem in combination with the xaml above
DataContext = MainViewModel;
InitializeComponent();
}
}
}
In order to get rid of the problem, I deleted one of the DataContext setters; it works with either the data context set in xaml or the data cantext set in the code behind, not both.
P.S. I add this answer because this is the first answer to come up on searches for this problem and I felt that further explanation would be useful to other visitors.

What makes visual studio's designer kick in for design time support

I have a c# control library which contains my models, viewmodels and views. I hook everything up as I usually do but I do not get any design time feedback from visual studio's designer (blendability).
When I load my assambly in a WPF project and include the view as custom user control I'll get my design time feedback. Unfortunately this WPF Project is only a test shell because the view will live in another app.
It would be more efficient for my dev pipeline if I could have blendability (design time) support in my class library? What makes visual studio kick in to show my design time datacontext?
I even use d:DataContext="{d:DesignInstance dd:DesignViewModel}" in my class library. No design time data in class library.
Try
d:DataContext="{d:DesignInstance dd:DesignViewModel, IsDesignTimeCreatable=True}
There is a blog here that may help you too.
I found it really frustrating having to create either an empty constructor for my viewmodels, or to make derived classes all the time, just to please the WPF designer.
One solution that works for me (tested only with Visual Studio 2013) is using a static property to expose an instance of a design-time view model, for example
C# code
namespace WpfApplication2
{
public class Person
{
public Person(string id)
{
Id = id;
}
public string Id { get; private set; }
}
public static class DesignViewModels
{
public static Person Person
{
get { return new Person("Design time person id"); }
}
}
}
and the XAML
<Window x:Class="WpfApplication2.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:my="clr-namespace:WpfApplication2"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<d:DesignProperties.DataContext>
<x:Static Member="my:DesignViewModels.Person" />
</d:DesignProperties.DataContext>
<TextBlock Text="{Binding Id}"/>
</Window>

Resources