How do I provide a custom data as a DataProvider for ImageTilesLayer on a mapControl in XAML file? - xaml

How do I provide a custom data as a DataProvider for ImageTilesLayer on a mapControl in XAML file?
I am new to WPF and DevExpress. I was trying a few examples given in the DevExpress documentation site.
Link: How to Load Image Tiles from Another Source
In the example, How to Load Image Tiles from Another Source given in their site, the DataProvider for a ImageTilesLayer is assigned in the code behind file.
Is it possible to mention the same DataProvider in the XAML instead of the code behind file?

You can assign the ImageTilesLayer.DataProvider property in XAML as follows:
<dxc:MapControl>
<dxc:ImageTilesLayer>
<dxc:ImageTilesLayer.DataProvider>
<local:CustomMapDataProvider/>
</dxc:ImageTilesLayer.DataProvider>
</dxc:ImageTilesLayer>
</dxc:MapControl>
P.S.
For more information about XAML properties syntax, see XAML Overview (WPF)-> Property Element Syntax MSDN article.
For more information about custom types in XAML, see XAML and Custom Classes for WPF.

Coding Horror, I would suggest you first read the tutorials given by DevExpress.
Link to the tutorials is below.
https://documentation.devexpress.com/#WPF/CustomDocument10682
It explains the different layers on map control.
Once you have read that, read on how to load images from different source
https://documentation.devexpress.com/#wpf/CustomDocument11174
In the code, instead of giving a url, change it to a local image folder where you have cached all the map tiles.
public class CustomTileSource : MapTileSourceBase {
const string roadUrlTemplate =
#"http://{subdomain}.tile.openstreetmap.org/{tileLevel}/{tileX}/{tileY}.png";
You can know more about caching at https://documentation.devexpress.com/#WPF/CustomDocument12205

Related

QML Component Screen Rendering

Is it possible to capture the screen rendering of a QML Component and save it to an image file? I would like to drive a Component through several different states, and capture its visual appearance for documentation purposes, without having to do screen/window captures.
Yes, you could set up your state transitions to call QWidget::grab then save it to a file through QPixmap.
If you need an example of how to set up your code to call QWidget::grab take a look at this answer: How to take ScreenShot Qt/QML
It's important to replace QPixmap::grabWidget with QWidget::grab because QPixmap::grabWidget is now obsolete. Once you have the QPixmap from QWidget::grab follow the documentation in QPixmap to save to the format you'd like such as jpeg, png, gif.
Here are some links to the documentation to help you out.
QWidget::grab
QPixmap
QPixmap::save
With Qt 5.4 it is now made easier with grabToImage - this method resides on all QQuickItem objects.
EDIT
It's worth mentioning that the item you call grabToImage() on must be a child of a top-level Window item container

How to save Image Control to local file in Windows 8?

I'm writing Client-Server application, in which I get item with Image Url. This Url is binded with Image control:
<Image Source{Binding ImageUrl} x:Name="img_avatar" Stretch="UniformToFill" Width="48" Height="48"/>
I want to save the image from Image.Source to the local folder without any methods which are using download operations.
Please help m someone !!!
There is no way to do what you ask about. When you set an Image control's source to a Uri - it gets converted to a BitmapImage which doesn't expose any API that would let you save the file or even extract a bitmap. If you want to avoid multiple downloads of the image you can download it as a file once and load a BitmapImage from the file instead of Uri.
I believe with a little bit of reflection hackery, it should be doable. But a lot better solutions exist, so yeah..
Either subclass Image or write attached property to handle logic. All you have to do, is just load image yourself into MemoryStream and create BitmapImage manually(behind subclassed Image or attached proeprty).
This way you can expose new property that gives direct access to MemoryStream, and from there you can save file to HDD without wasting precious memory.
Bonus points if you can also keep the Source="{Binding}" syntax while providing this functionality.

Page Navigation in Windows 8 XAML (without using code behind)

For my windows 8 application i am trying to navigate between pages with out using code behind.
For example, i have one image in my UI without creating tapped event for that image i need to navigate to another page,
<Image Source="ms-appx:///Assets/Logo.png" Width="155" Height="110" Tapped="{ // Navigation method here }"/>
Is it possible to navigate between pages like this...? If possible, how can i get this to work??
XAML is just a declarative language without action part so code behind is an essential part of it.
All interactions work via events and event can be handled in a code behind only. So what you want is not possible with XAML(at least with WinRT XAML).
If you are asking if you can specify the code inside the .xaml file, then no, that is not possible.
If you are asking if you can avoid adding code to the .xaml.cs file, then yes, that is possible. You will still need to specify a method but it can even be done as a simple lambda. You will need to use the Command hooks rather than the Event Hooks, e.g.
<Button Command="{Binding GoConnectionCommand}" ... />
The code for this command is usually defined in the ViewModel as part of the MVVM pattern, and Josh Smith explains it far better than I will.
AlSki mentioned using a ViewModel. Although technically the ViewModel is not part of the "code behind" for the XAML file, it's still code and I believe you were asking for a no code solution.
ixSci is correct that there is no way to do this out of the box without code behind in WinRT XAML.
In full WPF it's possible to do this using a behavior called NavigateToScreenAction. You can read about it here. Unfortunately behaviors don't ship out of the box with WinRT, but they can be added back in by an open source project called WinRtBehaviors.
There is no NavigateToScreenAction behavior for WinRT, but one could be created. There is a good article on creating behaviors with the library here. It will obviously require code to create the behavior, but after it's created you could use it in XAML without any code.
Really, the short answer is it's not possible to navigate without code on WinRT.
Dev support, design support and more awesome goodness on the way: http://bit.ly/winappsupport

How efficient is XAML parsing in WinRT / Win8?

When creating UserControls, it looks like the XAML is being parsed every time the control is initialized.
For example, when I create a UserControl, there's auto-generated code to initialize the component that looks like this:
public void InitializeComponent()
{
if (_contentLoaded)
return;
_contentLoaded = true;
global::Windows.UI.Xaml.Application.LoadComponent(this, new global::System.Uri("ms-appx:///Views/MyView.xaml"), global::Windows.UI.Xaml.Controls.Primitives.ComponentResourceLocation.Application);
}
This existed in Silverlight as well.
Creating the control once or twice is not a big deal, but if I have a large visual tree in each UserControl with Visual-States and bindings, and I'm creating it many times per application lifecycle, it would make sense to build the visual controls using C# to boost performance.
So, my question is:
Does the parser/framework "remember" the XAML file and avoid re-parsing it again on subsequent calls? That is, does it create a binary representation of the XAML so it doesn't have to read text all over again?
It's my understanding that XAML gets compiled into a binary form as a resource within your application. The runtime does not have to parse the text of the .xaml file, just as it does not have to parse your .cs code files.
The performance of instantiating the classes as declared with XAML is supposed to be on par with creating it in code.
Windows 8.1 xaml finally added XAML binary format :)
XAML Binary Format: The final signed appx will no longer contain text based markup as it will get converted into Binary.

Plugin.ImageResourceName doesn't seem to have any effect

It would be great if the Petrel Plugin Manager could display our custom bitmap for each of our plugins - however, the Plugin.ImageResourceName property doesn't seem to have any effect.
public override string ImageResourceName { get { return "Blueback.Toolbox.Plugin.Toolbox.png"; } }
The image is embedded correctly (according to the documentation and ILDisAsm) - but Plugin Manager insists on using the generic image instead. Are there undocumented requirements on dimensions or format? The code snippets in the documentation mention both bmp and png, without demonstrating that the property actually works.
I haven't been able to locate an actual running sample in the SDK (only Module samples) nor in the code sample downloads (several Plugins here, but they return null for the resource name).
Can anyone provide a working sample or the missing key?
The image provided via Plugin.ImageResourceName is displayed in the Petrel License Dialog, and you are right, it is not displayed in Plugin Manager as it always uses the generic image to represent plugins. We will consider changing it in Petrel 2013.1.