If you create an out-of-the-box WinRT phone app in Visual Studio, e.g. a Hub App (Windows 8.1 Universal), the resulting XAML loads design time data in XAML like this:
<HubSection
IsHeaderInteractive="True"
DataContext="{Binding Section3Items}"
d:DataContext="{Binding Groups[3], Source={d:DesignData Source=../HubApp1.Shared/DataModel/SampleData.json, Type=data:SampleDataSource}}"
x:Uid="Section3Header"
Header="Section 3"
Padding="40,40,40,32">
This design time data parsed in from a JSON file is visible in Blend:
I want to move the JSON file loading and parsing out of XAML and into C#, and have it still available in Blend. How do I do that? The challenge I face is that to be available in Blend I think the C# has to use a parameterless constructor. But loading a file (in WinRT) is asynchronous. Hence the method that opens the file must either be marked async and use await, or use a ContinueWith continuation. However async and thus await are not allowed in constructors and anything in a continuation appears to happen after the page loads into Blend and is not reflected in the Blend design view.
How do I load design time data, parsed from file, into Blend in code in WinRT?
(N.B. This is a generalisation of another question.)
You can always block the thread waiting for the task to finish using task.Wait() or task.Result (if you need the result).
Related
I have added the below line of code in App.xaml.cs for enabling xaml compilation in all the pages.
[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
namespace MyApp
{
}
Also I have added this line of code in my one of the xaml views to enable ZIndex in a specific control for Android.
xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
android:VisualElement.Elevation="10"
So my doubt is, Is it affect the Xaml compilation? If I add the above line of code is it affect my View's Performance?
Note: I am assuming you are using a .NetStd library project and not a Shared Code project as the "container
" of your XAML code and that you are also using the latest version of Xamarin.Forms
android:VisualElement.Elevation="10"
VisualElement.Elevation will become a Forms-based bindable property attached to each control that you are assigning it in when compiled into IL via XAMLC, i.e.
IL_0085: ldsfld [Xamarin.Forms.Core]Xamarin.Forms.BindableProperty [Xamarin.Forms.Core]Xamarin.Forms.PlatformConfiguration.AndroidSpecific.VisualElement::ElevationProperty
So my doubt is, Is it affect the Xaml compilation? If I add the above line of code is it affect my View's Performance?
So it is compiled into IL, the XAML is not embedded in the assembly and of course is present on all platforms that this cross-platform NetStd/PCL assembly is deployed (that is why a platform-based bound property is used). At runtime the property is assigned and yes there is an "overhead" associated to do that:
IL_008a: ldc.r4 10
IL_008f: newobj instance void [netstandard]System.Nullable`1<float32>::.ctor(!0)
IL_0094: box [netstandard]System.Nullable`1<float32>
IL_0099: callvirt instance void [Xamarin.Forms.Core]Xamarin.Forms.BindableObject::SetValue([Xamarin.Forms.Core]Xamarin.Forms.BindableProperty,object)
Note: This "overhead" is on all platforms, it would just be on Android that setting the "native" field's Elevation would actually do anything.
Would it be faster and more memory efficient to directly assign the Elevation in a custom Android renderer, yes, but only you can determine if the (small) gain is worth it to your code base.
I am working on a Visual Studio Extension. I am trying to get the ID of a code review request after it has been created/saved. I have added my own ITeamExplorerSection to the RequestCodeReview page. It makes sense to me that In my implementation of the SaveContext method of my section that I should be able to call the GetExtensibilityService on the page and retrieve the "CodeReviewId". I have several issues with this, the most important of which are: What object type am I trying to retrieve? and second is it available in the SaveContext Method. (or is this even the right approach)
I have "DOM like" data structure in c# (parent, childNodes, properties, enums...) and I want to use xml\xaml file to some of the initializing. I already wrote a tool that transform my xaml to c# and inject them in the right place.
I want the exact Intellisense behavior of WPF except that my classes doesn't inherits from WPF base classes and my project in not wpf application on library and doesn't reference wpf assemblies. i also don't want to use xsd schema because classes are added and edited very frequently.
I'm using visual studio 2010
Is it possible?
Create a xaml (start by creating a resource dictionary and delete the content).
Add your own assembly as the default namespace and start using your types. I have created a test for sample data recently, here's how it looks like:
<MainViewModel xmlns="clr-namespace:MvvmTest.ViewModels.DesignTime"
Name="The design time main view model">
<MainViewModel.SubViewModels>
<FirstSubViewModel Name="The design time first sub-view model" />
<SecondSubViewModel Name="The design time second sub-view model" />
</MainViewModel.SubViewModels>
</MainViewModel>
You can load the file using the XamlReader class. As a bonus compared to xml, the file will be compiled and run time loading will be much faster.
I'm creating a small Windows application (C++) which create some windows an such (CreateWindowEx and the like). And in one window I want to add a control that shows MHTML loaded from memory, i.e. the whole MHTML content is in a string, not in a file.
I already tried the Shell.Explorer component, but I can't find a way to inject to it anything other than HTML (see AtlAxCreateControl).
Is it possible to use the Shell.Explorer component or any other to show in-memory MHTML??
That is, without writing the content to a file and then giving the file path. That works, but it's not optimal and it'll have to be the last alternative if I can't do it any other way.
PS: If this can be done in another language or environment like C#, JS, VBS, WSH, HTAs, I'm all ears as well.
A bit late to answer, but still - there is a way to do it : use Microsoft's WebBrowser control (COM component, can be used in .Net apps as well).
Take a look an what the proposed solutions here - How to load mht from stream/string into a WebBrowser control? and here - How to display the string html contents into webbrowser control?. some of them refer to mhtml content but the solutions are applicable to ordinary html files as well.
Good luck.
I have modified some code inside my Firefox. Just add on some extra functions for my isolation network. Besides that I also want to create my own FF extension for this particular purpose. I just need some information:
Can the code inside my Firefox, call any function Javascript declared in my extension?
Generally yes, but your question is not specific enough. Both Firefox and an extension can have JS and C code, code in XPCOM components, code running in a specific window, JS modules, etc.
Assuming the "Firefox code" is running in some window (e.g. you edit browser.js) and the "extension function" you want to call also exists in that window (e.g. you overlay chrome://browser/content/browser.xul, which is the URI of the main Firefox window, in which the browser.js code runs), you can just call it as you would normally do.