PivotViewer v2 dynamic collection AND deep zoom images - c#

I am using the PivotViewer v2 released with Silverlight 5. I've started to use the new data binding ability of the PivotViewer, binding directly to data objects that are passed down from the server, and using an ItemTemplate to display the objects in the PivotViewer.
With CXML, I could pre-generate the DZCs/DZIs for the pivot viewer (it's a JIT collection), but I can't figure out how to use Deep Zoom imaging + the new Pivotviewer with data binding. How can I display a deep zoom image in an item template for a collection that is data bound?
I've tried using the PivotViewerMultiSizeImage class (XAML below) and the PivotViewerMultiScaleSubImageHost class. My example below almost works: it displays an image, but seems to be stuck at the 100 pixel level - no Deep Zoom. I've also tried the MultiScaleImage control with DZIs, but no luck - it generates an OutOfMemory exception immediately.
Does anyone know how to get Deep Zoom capability with data binding in the new PivotViewer?
<pivot:PivotViewer.ItemTemplates>
<pivot:PivotViewerItemTemplate>
<pivot:PivotViewerMultiSizeImage Width="100" Height="100">
<pivot:PivotViewerMultiSizeImage.Sources>
<pivot:PivotViewerMultiSizeImageSource MaxHeight="100" MaxWidth="100" UriSource="{Binding Images[2]}" />
<pivot:PivotViewerMultiSizeImageSource MaxHeight="300" MaxWidth="300" UriSource="{Binding Images[3]}" />
<pivot:PivotViewerMultiSizeImageSource MaxHeight="500" MaxWidth="500" UriSource="{Binding Images[4]}" />
<pivot:PivotViewerMultiSizeImageSource MaxHeight="700" MaxWidth="700" UriSource="{Binding Images[5]}" />
<pivot:PivotViewerMultiSizeImageSource MaxHeight="20000" MaxWidth="20000" UriSource="{Binding Images[6]}" />
</pivot:PivotViewerMultiSizeImage.Sources>
</pivot:PivotViewerMultiSizeImage>
</pivot:PivotViewerItemTemplate>
</pivot:PivotViewer.ItemTemplates>

I've implemented binding to a collection of objects but am using a deep zoom collection for the images. I used the Excel tool but only gave it the path to the images (sorted by Name) and a name. I didn't use the cxml file, but did use all of the rest of the deep zoom image files. I added a property to the data objects in the collection, called Img. Img is the image number index in the image collection for that object (0 based). Then, my PivotViewer ItemTemplate binds to this property. The CollectionSource property is set to the path to my image collection xml file(it is named in the generated cxml).
<Visualizer:MyPivotViewer x:Name="RedemptionPivot" >
<Pivot:PivotViewer.ItemTemplates>
<Pivot:PivotViewerItemTemplate >
<Pivot:PivotViewerMultiScaleSubImageHost ImageId="{Binding Img}" CollectionSource="http://www.redemptionlive.com/Visualizer5/RedemptionCards_files/e3tbc2s0.4td.xml"/>
</Pivot:PivotViewerItemTemplate>
</Pivot:PivotViewer.ItemTemplates>
<Pivot:PivotViewer.PivotProperties>
<Pivot:PivotViewerStringProperty Id="Name" Options="CanFilter,CanSearchText" DisplayName="Name" Binding="{Binding Name}" />
<!--The rest of the properties go here-->
</Pivot:PivotViewer.PivotProperties>
</Visualizer:MyPivotViewer>

You're getting a 100x100 image because you are specifying this as the size of your control. Change the size of
<pivot:PivotViewerMultiSizeImage Width="100" Height="100">
to
<pivot:PivotViewerMultiSizeImage Width="2000" Height="2000">
or something big enough to cause the largest image to show. Also, I'm not sure if this matters or not, but I didn't put a MaxHeight/MaxWidth on my largest image.
This worked for me, thanks for halfway figuring this out because you lead me down the right path to getting deep zoom like functionality with databinding!

Related

MediaElement XAML -> AutoPlay not a property?

I have created a MediaElement in XAML and assigned a .mpg as the source.
Looking at the XAML controls gallery from Microsoft, there are some examples such as:
<MediaPlayerElement Source="Assets/SampleMedia/fishes.wmv"
MaxWidth="400"
AutoPlay="True" />
However, I am faced with invalid markup that is returning:
The property AutoPlay was not found in type MediaElement
I have tried removing the AutoPlay and using a MediaOpened event to start the video from code behind,but there is never any trigger even?
I am not having too much success.
DO I need to add any additional resources to access certain properties?
<MediaElement x:Name="backdropMotion" Source="Images/inMotion_video.mpg"
Stretch="Fill" Margin="198,126,-326,229" Grid.Column="2"
LoadedBehavior="Play" IsEnabled="True" IsMuted="True"
Grid.Row="1" Grid.ColumnSpan="2" MediaOpened="MediaOpenedEvent"
AutoPlay="True"
>
Ultimately, I am trying to run a media element to a panel that effectively acts as an animated background, looping almost like a .gif. First step is to get the element running.

WPF MVVM Chartplotter: Dynamically bind multiple Lines

I'm trying to make the WPF Chartplotter work with some WPF MVVM. As a target of my interest I've chosen our TeamCity Tests Performance. The current Plotter is looking like this:
<dd:ChartPlotter Grid.Row="1">
<dd:ChartPlotter.HorizontalAxis>
<dd:HorizontalIntegerAxis />
</dd:ChartPlotter.HorizontalAxis>
<dd:ChartPlotter.VerticalAxis>
<dd:VerticalIntegerAxis/>
</dd:ChartPlotter.VerticalAxis>
<dd:VerticalAxisTitle Content="Performance in Minutes" FontSize="10" />
<dd:HorizontalAxisTitle Content="Build by ID" FontSize="10" />
<dd:LineGraph DataSource="{Binding TestRunsPerformance, IsAsync=True}" Stroke="Green" StrokeThickness="2">
<dd:LineGraph.Description>
<dd:PenDescription DescriptionString="Test" />
</dd:LineGraph.Description>
</dd:LineGraph>
<dd:LineGraph DataSource="{Binding TestSlowRunsPerformance, IsAsync=True}" Stroke="Red" StrokeThickness="2">
<dd:LineGraph.Description>
<dd:PenDescription DescriptionString="TestSlow" />
</dd:LineGraph.Description>
</dd:LineGraph>
</dd:ChartPlotter>
</Grid>
So I have basically two Test-Categories and for each I show a LineGraph in the Plotter, which I bind to the EnumerableDataSource in the ViewModel. Unfortunately I couldn't test it, but I'm certain it will work this way, since one LineGraph did work so far.
This is cool, but now I would like to make a second Chart with the Unit-Tests with the highest influence. But for this, I can't just create LineGraphs in the XAML and bind, but I would need something like a LineGraph Collection and set an amount of LineGraphs dynamically. Since I'm also learning MVVM, it would be troublesome If I'd really need to do this in the Code behind.
Unfortunately, all the Examples I found so far do exactly this, for example: Dynamic Line chart in C# WPF Application
I found also examples to make this work for Canvas: Is it possible to bind a Canvas's Children property in XAML? but these are UIElements, not PlotterElements.
Is what I'm trying even possible or am I doing something fundamentally wrong?

how to clear image control from local path

i have a image control in wpf like this
<Image x:Name="Img" Source="{Binding IsAsync=True}" />
i set the image by fetching from a url like this
Img.DataContext = ImageUrl;
it shows fine and when i want to clear it i just use
Img.DataContext=null;
for the same control i have a browse button as well to select the image from local path like this
BitmapImage image = new BitmapImage(new Uri(path));
Img.Source=image;
now i want to clear that as well so i do
Img.Source=null;
after that the control wont show the image from url only local images can be opened
Edit: probably i need to set the binding again after making source to null, not sure how to do that
You are abusing bindings horribly. Please stop.
<Image x:Name="Img" Source="{Binding IsAsync=True}" />
Says "Bind to the data context", which isn't all that great. Bind to a property of your view model, something like:
<Image x:Name="Img" Source="{Binding Path=ImageLocation, IsAsync=True}" />
And then only ever change the image using ImageLocation. At the very least, only set it via the DataContext.
Once you set the source to a binding, you should never be changing it via code-behind. Period. Do that, and your problem will "magically" disappear, as you are doing it the right way now.
To clear image control, clear image url.
e.g imgControlName.ImageUrl = "";

WP7 App: Too large page

I have created a small WP7 app which contains one page which is dynamically filled with content. But it goes out of viewable area. Emulator doesn't scroll the page when I click-hold-move on the screen. How do I make it scroll when needed?
One simple option is to drop the content you require inside a ScrollViewer, so for example adding a large TextBlock as so:
<ScrollViewer Name="scrollViewer" ScrollViewer.HorizontalScrollBarVisibility="Visible" >
<TextBlock Height="30" Name="textBlock" FontSize="24"
Text="This is a long block of text which wont fit in the available area" />
</ScrollViewer>
Obviously, in most cases you will want to drop a container control such as Grid or StackPanel into the ScrollViewer and place all your other controls in there.
That said, I'm wondering if you are actually looking for some of the standard WP7 Metro look and feel controls such as the Panorama and Pivot Controls which are available in the latest dev tools - follow that link for full details.

OnScreen event in wpf

I have a small custom control which downloads & displays a contacts image. It ensures that only 1 image is being downloaded at a time by adding itself to a static queue of images awaiting to be downloaded.
It is possible to get quite long contact lists. So I want it to only enter the download queue when it actually becomes visible on the screen (there's a default image).
I've tried placing the logic in the Loaded event, overriding OnRender and the IsVisibleChanged event, but none seem to give me what I want.
any suggestions?
D.R
Edit:
This is a WPF Application, sorry for not mentioning before...
Some system controls (like ListView) have property "VirtualMode" if you set it to true and handle RetrieveVirtualItem event. This event invokes for items which are visible currently and you have to fill those items with data(images) you want. So that you don't need to fill all items at once.
Have you considered using a PriorityBinding in order to provide that functionality?
<DataTemplate DataType="{x:Type vm:MyViewModel}">
<StackPanel Orientation="Horizontal">
<Image>
<Image.Source>
<PriorityBinding FallbackValue="{StaticResource ImgDownloading}">
<Binding Path="ImageSource" IsAsync="True" />
</PriorityBinding>
</Image.Source>
</Image>
<Label Content="{Binding Name}" />
</StackPanel>
</DataTemplate>

Categories

Resources