navigationservice has no constructors defined - windows-phone

I am using Visual Studio Express 2012 for Windows Phone and building an app targeting Windows Phone 7.1.
I am trying to use NavigationService to navigate to a different page but I keep running into problems.
Here is my code:
private void GotoDetails(object _url)
{
var url = string.Format("/DetailsPage.xaml?url={0}", _url.ToString());
NavigationService nav = new NavigationService();
nav.Navigate(new Uri(url, UriKind.Relative));
}
when I try to build this I get a "The type 'System.Windows.Navigation.NavigationService' has no constructors defined" on the NavigationService nav =.... line.
If I try to do just NavigationService.Navigate(new Uri(url, UriKind.Relative)); then I get a "An object reference is required for the non-static field, method, or property 'System.Windows.Navigation.NavigationService.Navigate(System.Uri)'" error.
update: I am trying to use MVVM (for the first time). This code resides in my view model. I am not using any frameworks. Just trying to learn it from scratch.
I have searched the intertubes but cannot seem to find a solution.
Any help is much appreciated.
Kamal

are you inside a page? NavigationService is a property of the Page class: http://msdn.microsoft.com/en-us/library/system.windows.controls.page.navigationservice(v=vs.92).aspx

Related

UWP SyncFusion SfDataGrid Serialization Exception

I'm trying to make use of the SfDataGrid component in my UWP app and have everything working just fine in debug mode. When I switched over to release mode to regression test the app before publishing to the Windows store the app throws an exception during grid serialization.
I have an SfDataGrid defined with 4 text columns, 1 numeric column and 1 template column. The template column just includes a delete button so that the user to can remove the row.
I have a method to return the serialization options as follows:
private SerializationOptions GetGridSerializationOptions()
{
return new SerializationOptions
{
SerializeFiltering = false,
SerializeColumns = true,
SerializeGrouping = true,
SerializeSorting = true,
SerializeTableSummaries = true,
SerializeCaptionSummary = true,
SerializeGroupSummaries = true,
SerializeStackedHeaders = true
};
}
Then I have another method to serialize the grid settings as follows:
private void RetrieveDefaultGridSettings()
{
using (MemoryStream ms = new MemoryStream())
{
gridReport.Serialize(ms, GetGridSerializationOptions());
_defaultGridSettings = Convert.ToBase64String(ms.ToArray());
}
}
I've followed the SyncFusion documentation (https://help.syncfusion.com/uwp/datagrid/serialization-and-deserialization) which describes how to serialize template columns. I have everything working perfectly in debug mode, but when I switch to release mode I get an exception on this line:
gridReport.Serialize(ms, GetGridSerializationOptions());
The exception is:
System.Runtime.Serialization.InvalidDataContractException: 'KnownTypeAttribute attribute on type 'Syncfusion.UI.Xaml.Grid.SerializableGridColumn' specifies a method named 'KnownTypes' to provide known types. Static method 'KnownTypes()' was not found on this type. Ensure that the method exists and is marked as static.'
I've had a look at the SerializableGridColumn class and can see a public static method called KnownTypes so I don't really understand why this exception is happening. I'm even more confused about why it's only happening in release mode.
In attempt to fix the problem I have tried referencing the entire SDK, removing the SDK and referencing the specific assemblies (Syncfusion.SfGrid.UWP, Syncfusion.Data.UWP, Syncfusion.SfInput.UWP, Syncfusion.SfShared.UWP, Syncfusion.SfGridConverter.UWP, Syncfusion.XlsIO.UWP and Syncfusion.Pdf.UWP) but neither yields a different result and the exception still occurs, but only in release mode.
Switching off the setting "Compile with .NET Native tool chain" does resolve the problem, but is not a practical solution as this blocks me from publishing the app to the Windows store.
Thanks very much for any assistance anyone can provide.
After exhausting all possible problems with my own code, I logged with an issue with SyncFusion. They're investigating and will hopefully provide a fix soon.

Extend Office JavaScript API with own Browser Control

I'm trying to write a VSTO-Add-In with a System.Windows.Forms.WebBrowser-Control enabling something similar to the Office-JS-Add-In model.
The WebBrowser-control would show some HTML/JS-Page and be able to call C#-functions in the VSTO-Add-In from JavaScript via window.external and the ObjectForScripting-property of the WebBrowser-object.
That is in JS the call would be
window.external.DoFancyStuffToMyDocument(withTheseParams)
while there had to be some
class MyFunctionProxy() {
public void DoFancyStuffToMyDocument(string theParam) {
//code here
}
}
in the C#-Code an this would be attached to the WebBrowser
myWebBrowser.ObjectForScripting = new MyFunctionProxy();
So far so good. Now comes the catch. I want my HTML/JS-Code be able to also utilize the office.js code and functions like
Word.run(function (context) {
var thisDocument = context.document;
var range = thisDocument.getSelection();
range.insertText('"Hitch your wagon to a star."\n', Word.InsertLocation.replace);
//...
}
Does anyone see a way of getting this to work?
My initial guess was that the OfficeJS-taskpane-add-ins in Word on-prem use some some similar methode as above with a class derived from WebBrowser and the appropriate ObjectForScripting. This would then suggest that there must be a (hopefully accessible) class which is assigned to the ObjectForScripting-property handling the function calls from office.js. Then I could proxy this ObjectForScripting-class and add my own functions like 'DoFancyStuffToMyDocument()'.

Loading XAML workflow with multiple activity assemblies

I have a XAML workflow which, which uses custom activities that are stored in more than one dlls. I’m trying to execute this workflow using WorkflowApplication. However I cannot figure out how to resolve multiple reference assemblies, while loading the XAML. I’m aware that the XamlXmlReaderSettings provides a LocalAssembly property, which allows us to provide the reference assembly. However, it only allows to provide a single assembly. How do I provide multiple reference assemblies to the reader, so that it is able to resolve the external types? Any help will be greatly appreciated. I’ve pasted the code I’m using for reference.
public void LoadWorkflowFromFileAsync(string workflowXaml, Assembly activityAssembly)
{
var xamlReaderSettings = new XamlXmlReaderSettings
{
LocalAssembly = activityAssembly
};
var xamlSettings = new ActivityXamlServicesSettings
{
CompileExpressions = true
};
using (var reader = new XamlXmlReader(workflowXaml, xamlReaderSettings))
{
_activity= ActivityXamlServices.Load(reader, xamlSettings);
}
}
Does your xmlns in the XAML include the assembly name (ex. xmlns:ede="clr-namespace:Sample.MyActivityLibrary;assembly=Sample.MyActivityLibrary")?
I'm not aware of anyway to reference multiple local assemblies in XamlXmlReaderSettings but if the assembly is referenced in the XAML it should resolve automatically.

Display ViewPart in eclipse

I am currently developing an eclipse plugin which displays DOT-Graphs. For this purpose I make use of this plugin. However, I have no idea how to actually display the graph which I built. I want to display it in the middle of the eclipse window as an Editor.
To get this done I created a custom Editor class which needs some code in its createPartControl(Composite) code in order to make use of the DotGraphView which is provided by the plugin.
The question is, how can I display this DotGraphView?
The code of my Editor looks like this:
#Override
public void createPartControl(Composite container) {
DotImport importer = new DotImport(TEST_GRAPH);
Graph graph = importer.newGraphInstance();
DotGraphView dotGraphView = new DotGraphView();
dotGraphView.setGraph(graph);
// add dotGraphView as a child to container and display it
// What todo here?
}
To use the graph in your own custom view, check out the implementation of ZestFxUiView, the superclass of DotGraphView. You could probably subclass ZestFxUiView and call setGraph with your graph object.

ViewComponent not found after upgrading Monorail from v1.0.3 to v2.1RC

I'm using Monorail in my C# web application. Since I upgrated it (.Net Framework 2 to 4 and Monorail 1.0.3 to 2.1RC), my ViewComponent class is not found. All my controllers seem to work fine. I'm using nVelocity View Engine. I'm not using Windsor, but maybe now I'm suppose to register it in a certain way?
In the .vm file, I experimented the following lines (without success, the first one was working before I upgraded the project) :
#component(MenuComponent)
#component(MenuComponent with "role=admins")
#blockcomponent(MenuComponent with "role=admins")
Did anyone experiment that?
The full error message is:
ViewComponent 'MenuComponent' could
not be found. Was it registered? If
you have enabled Windsor Integration,
then it's likely that you have forgot
to register the view component as a
Windsor component. If you are sure you
did it, then make sure the name used
is the component id or the key passed
to ViewComponentDetailsAttribute
Many thanks!
I finally found a clue to my problem. I used 'Castle.Monorail.Framework.dll' source code to see what happen inside : it seems that assemblies specified in the Web.Config file (in <Controllers> or even in <viewcomponents>) are not 'inspected' as they are supposed to be because the variable which contains it is initialized too late.
I builded a new version of the dll and now it's working fine. I will submit my 'fixed' code to the Castle Project Community to be sure it's not the consequence of something else (like bad settings).
Til then here is my 'fix', I just moved a portion of code. You can find the original source code here : http://www.symbolsource.org/Public/Metadata/Default/Project/Castle/1.0-RC3/Debug/All/Castle.MonoRail.Framework/Castle.MonoRail.Framework/Services/DefaultViewComponentFactory.cs
*Assembly:* Castle.MonoRail.Framework
*Class:* Castle.MonoRail.Framework.Services.**DefaultViewComponentFactory**
public override void Service(IServiceProvider provider)
{
/* Here is the section I moved */
var config = (IMonoRailConfiguration)provider.GetService(typeof(IMonoRailConfiguration));
if (config != null)
{
assemblies = config.ViewComponentsConfig.Assemblies;
if (assemblies == null || assemblies.Length == 0)
{
// Convention: uses the controller assemblies in this case
assemblies = config.ControllersConfig.Assemblies.ToArray();
}
}
/*******************************/
base.Service(provider); // Assemblies inspection is done there
var loggerFactory = (ILoggerFactory) provider.GetService(typeof(ILoggerFactory));
if (loggerFactory != null)
{
logger = loggerFactory.Create(typeof(DefaultViewComponentFactory));
}
/* The moved section was here */
}
I'm curious, without your fix, if you rename MenuComponent to just Menu, does it work?