How do you define a single blendable design time instance? - data-binding

The default Windows 8 project template has a CollectionViewSource in the template.
<CollectionViewSource
x:Name="itemsViewSource"
Source="{Binding Model.Invitations}"
d:Source="{Binding Invitations, Source={d:DesignInstance Type=vm:DesignerFilteredInvitations, IsDesignTimeCreatable=True}}" />
Obviously not all pages have a collection as their model, you can define a DataContext like this:
<vm:MySingleItemViewModel x:Key="Model" />
How do you define the design instance for this kind of model?

Well, design time data is best accomplished like this: http://blog.jerrynixon.com/2012/08/most-people-are-doing-mvvm-all-wrong.html
I realize your question is asking about using d:DesignInstance which also works with this type of technique - just not demonstrated in that article.
All it requires is a good constructor.

Okay, using this works fine:
<Page
d:DataContext="{d:DesignInstance Type=Models:ViewModel, IsDesignTimeCreatable=True}"
And using this works fine:
<d:Page.DataContext>
<Models:ViewModel/>
</d:Page.DataContext>
I must tell you the latter is an easier approach, too. It is also what Visual Studio will generate when you setup a data source in the designer. It also gives you fully-typed bindings. But either is acceptable.
Another note. I can see no good reason to set an object directly to the source of a CollectionViewSource. Normally you would be binding the CVS's Source property to a property inside your ViewModel. But, given your question: Here's how:
<CollectionViewSource
x:Name="TestCVS" Source="{Binding}"
d:DataContext="{Binding Source={d:DesignInstance Type=Models:ViewModel, IsDesignTimeCreatable=True}}"/>
Binding to the Source in the designer caused me endless trouble. But it irritated me more because I knew I would never do it this way. This is what I wanted to do:
<d:Page.DataContext>
<Models:ViewModel/>
</d:Page.DataContext>
<Page.Resources>
    <CollectionViewSource x:Name="TestCVS" Source="{Binding}" />
</Page.Resources>
You better have a great reason for your approach!
Best of luck!

Related

Data binding to SfChart properties should work with elements in StaticResource?

We have a common DateTimeAxis that we refer to in all our content pages with an SfChart.
<xForms:DateTimeAxis
x:Key="CommonDateTimeAxis"
AxisLineStyle="{StaticResource ChartAxisLineStyle}"
EdgeLabelsDrawingMode="Shift"
Interval="{Binding DateTimeAxisIntervalGrouping}"
IntervalType="{Binding DateTimeAxisInterval, Converter={StaticResource DataTimeAxisTypeConverter}}"
MajorTickStyle="{StaticResource ChartMajorTickStyle}"
Maximum="{Binding CurrentDataWindow.End}"
Minimum="{Binding CurrentDataWindow.Start}"
PlotOffset="12"
ShowMajorGridLines="False">
<xForms:DateTimeAxis.LabelStyle>
<xForms:ChartAxisLabelStyle
FontFamily="{StaticResource LightFontFamily}"
FontSize="10"
LabelFormat="{Binding DateTimeAxisDateFormat}"
TextColor="{StaticResource OffWhite}" />
</xForms:DateTimeAxis.LabelStyle>
</xForms:DateTimeAxis>
Note that we are binding to a ViewModel property as we change the format dynamically.
LabelFormat="{Binding DateTimeAxisDateFormat}"
On initial load of a page and viewmodel the setting of the format works fine. However if once we close the View\ViewModel then go back into any other of our View\ViewModels with sfChart (or the same one) the LabelFormat remains stuck on whatever value it was prior to closing the first View/ViewModel.
I thought I was doing something foolish with retaining instances but I then realised that if i simply declare the DateTimeAxis locally i.e. not a shared resource in a ResourceDictionary, the binding always works.
That's not expected right? FWIW I have opened an incident with Syncfusion seperately and will report anything useful back here
The reported issue has been fixed and moved to Syncfusion SfChart NuGet Version: 18.2.0.47

How to override template “folder_full_view_item.pt”?

This question is a reformulation of this question which had evolved in a confusing way. Please refer to this question if you search some in depth details or are interested in workarounds and alternative solutions.
This question is about the call to template folder_full_view_item.pt in folder_full_view.pt, not about other templates in general!
Please avoid workarounds like skin layers, editskinswitcher, etc. I don't want to solve a particular use case here. What I want is to really understand how this actually works.
I present this question in three parts: scenario, result, questions.
scenario
Have a Folder with a Document. The layout of the Folder is folder_full_view. The layout of the Document is document_view:
Folder (layout=folder_full_view)
Document (layout=document_view)
The template folder_full_view.pt calls template folder_full_view_item.pt via item.getObject().folder_full_view_item().
folder_full_view_item.pt calls (e.g. for a Document content type ) the template document_view.pt via use-macro="item_macro" (item_macro being something like here/document_view/macros/content-core). Schematically as follows:
folder_full_view.pt :: item.getObject().folder_full_view_item()
folder_full_view_item.pt :: use-macro="here/document_view/macros/content-core"
document_view.pt
In a plone3_theme have overriden versions of the templates folder_full_view.pt, folder_full_view_item.pt, and document_view.pt. These templates are registered as follows in configure.zcml.
<browser:page
for="*"
name="folder_full_view_item"
template="folder_full_view_item.pt"
layer="example.theme.browser.interfaces.IThemeSpecific"
permission="zope2.View"
/>
<browser:page
for="Products.ATContentTypes.content.folder.ATFolder"
name="folder_full_view"
template="folder_full_view.pt"
layer="example.theme.browser.interfaces.IThemeSpecific"
permission="zope2.View"
/>
<browser:page
for="Products.ATContentTypes.content.document.ATDocument"
name="document_view"
template="document_view.pt"
layer="example.theme.browser.interfaces.IThemeSpecific"
permission="zope2.View"
/>
results
With the theme installed the results are:
Document and Folder get their templates (I guess) via traversal. The (sub)templates though don't go through the traversal.
Folder: uses overriden folder_full_view.pt, original folder_full_view_item.pt, and original document_view.pt
Document: uses overriden document_view.pt
questions
is it the case that item.getObject().folder_full_view_item() doesn't go through traversal? If yes why?
what can be modified (in folder_full_view.pt!) to force a traversal to the overriden folder_full_view_item.pt(!) and subsequently to the overriden document_view.pt? Is this possible?
Again, please avoid workarounds like skin layers, editskinswitcher, etc. I don't want to solve a particular use case here. What I want is to really understand how this actually works.

Open direct links to AX-objects or datasets from external application

Is there a way to open a specified document, eg "production order 123" or form, eg "purchase orders" in Ax2012 from an external application directly?
In detail, I'm looking for something similiar like AXPath, but this doesn't work with versions greater then 2009.
Is there any ( maybe included ) way to achieve this?
There is! It's using AX's drilldown functionality which uses AxHLink.exe to handle dynamics:// URLs, which are passed to the Classes\SysStartupCmd function. You could also create some custom code there if you wanted to launch the AX client executable directly.
My question I asked some while back should have a great deal of useful information in it here:
What handles dynamics:// URLs?
Some more can be found: http://technet.microsoft.com/en-us/library/aa834337.aspx
EDIT:
It sounds like you are confused or the posts weren't clear enough. I think you have 3 basic options.
Dynamics:// URLs are handled by AxHLink.exe and they only seem to handle drilldown, viewalert, and viewalertrule. So if you want to use Dynamics:// URLs, you will need to hi-jack those somehow. There is a pastbin from Jan in that other stack post.
Create a custom URI handler and event poller (lot of work) see http://axcoder.blogspot.dk/2010/10/how-to-open-form-in-running-ax-from.html
Extend SysStartupCmd and then instead of using Dynamics:// URLs, just call Ax32.exe -startupCmd directly and a parameter can be passed to your custom class.

How to setup durandaljs with Areas?

For the life of me I can't make durandaljs work with Areas. I'm developing an application with multiple mini SPAs, but I'm not sure how to set up durandaljs to work with it. I wasn't able to find anything online that can drive me in the right direction. The only similar question I found was this one, which is very vague.
My goal is to separate each SPA within it's own folder like so:
App
--areas
----area1
------viewmodels
------views
----area2
------viewmodels
------views
The router doesn't seem to have the concept of areas and no matter how I map the routes I get 404s when I call router.activate('page1'); after mapping with router.mapRoute('page1'); durandal is trying to get /App/viewmodels/page1.js.
Changing it to:
router.mapRoute('areas/area1/viewmodels/page1');
router.activate('areas/area1/viewmodels/page1');
results in another 404 fetching App/viewmodels/areas/area1/viewmodels/page1.js
I've also tried many other combinations which I no longer remember and can't seem to get it to work.
Can someone please post a working example of how to setup durandaljs with the router plugin and multiple mini SPAs (areas)? A link to an article document would also suffice.
You can use viewLocator.useConvention - maybe something like this:
viewLocator.useConvention(
"areas/area1/viewmodels",
"areas/area1/views",
"areas/area1/templates"
);
One good thing to realize is that useConvention() works in conjunction with any existing require.config paths setting. In other words, if you set the require.config so that "viewModels" and "views" are mapped to the right folders, then all is well.
For example, the code snippet above is functionally equivalent to:
window.require.config({
paths: {
"viewModels": "areas/area1/viewmodels",
"views": "areas/area1/views",
"templates": "areas/area1/templates"
}
viewLocator.useConvention("viewmodels", "views", "templates");
I a similar structure implemented in my application. I think that you have to put this piece of code, to do the viewLocator works properly.
viewLocator.useConvention(); //You can do that in you main.js
You can see more information here: http://durandaljs.com/documentation/View-Locator/
Also I recommed you to look the code of viewLocator.js, especially, the code of useConventionMethod.
Other possibility is to override the method convertModuleIdToViewId, to make it works as you want. But I think that using useConvention methos is enought.

what isCOMCLASS attribute and how is used

I was checking some code , I found comClass attribute.
what is that and what is it used for?
is there any good articles about that?
Thanks
Pretty easy to find, yeah... https://www.google.com/search?rlz=1C1CHFX_enUS384US384&sourceid=chrome&ie=UTF-8&q=ComClassAttribute
First link: http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.comclassattribute.aspx
Fifth link: http://mikedimmick.blogspot.com/2005/09/what-does-vbnet-comclass-attribute-do.html
It seems to be relevant only to VB (as in, it's not relevant to C#, for example). See this:
http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.comclassattribute.aspx
Also, I thought this was a good read: http://blogs.msdn.com/b/vbteam/archive/2007/06/01/so-what-does-lt-comclass-gt-actually-do.aspx; it basically says this is how you'd make a VB.NET class visible to VB6.
Other related threads that I found:
Will VB.NET automatically generate ComClass attribute and guids?
http://mikedimmick.blogspot.com/2005/09/what-does-vbnet-comclass-attribute-do.html

Resources