|
Hello. Cheers for that, and thanks for always answering my questions.
|
|
|
|
|
Hi everybody! I'm a kind of newbie in WPF and I have an app, that shows in a ListBox images from some directory. I'm using recycling option and a converter to minimize images to 100 width. This realy decrease memory usage, but the case is that app's start takes some time (up to 2 minutes on 2000 5mp images). And this time depends on quantity of images linearly.. I think, that's because of app has to load all images in cash, and i want to perform quick start and then to load images needed. Also, when app starts memory goes up to 250 Mb on ~300 5mp images, and on loaded memory decreases to 70-80 Mb and stays steady. Any ideas?
|
|
|
|
|
I have not done any serious WPF yet so I didn't run into such situations. But I think this may solve your problem.
<ListBox VirtualizingStackPanel.IsVirtualizing="True" />
Please tell me if it works.
Eslam Afifi
|
|
|
|
|
It set to true all the time, but unfortunatly it doesn't solve the problem.
|
|
|
|
|
I've just got online and read Luc Pattyn's replies. I'd like to add to his/her advice using the MVVM pattern and store the thumbnails in the Model-View, or maybe in the Model itself. Make the converter checks if the thumbnail exists or not so you use the cached thumbnail or create and store it. You can keep the thumbnails in memory or on disk, whatever is best for your situation. All that while keeping the ListBox virtualizing.
Eslam Afifi
modified on Saturday, March 14, 2009 8:08 AM
|
|
|
|
|
Hi,
this problem is not specific to WPF. There generally are two remedies:
1. only load what is really necessary; having controls that support a "virtual" mode makes that easier.
2. compute "thumbnails" once, and store them on disk, together with the actual images. Don't worry about disk space, they could well be 100 times smaller than the originals.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
I'm using controls, that support "virtual" mode, and i think it work on scrolling, but i interest in faster startup. I don't know why it starts so long, and i assume that all the images are cached on load. Maybe i'm wrong, but i don't know another reason. That's why i need help. If it matter's, i can show code.
|
|
|
|
|
Hi,
improving the performance is similar to debugging, so gather the facts, analyze, formulate an hypothesis, verify, fix, and iterate.
These are the first steps I would take:
- install logging code, basically a "public static void log(string)" method that saves a string to a log file;
- set up a StopWatch, so each log message automatically gets prefixed with the elapsed time with millisecond resolution
- sprinkle log statements in the relevant parts of the app.
- now have a trial run: startup, stop, look at the log file; any time gap exceeding say 100 msec needs either more log statements, and if that is not possible, is a hotspot in need of fixing. It might be a Thread.Sleep() you forgot to remove, a first database access (move to another thread?), a first network access, etc.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
S.a.n.4.e.s wrote: i assume that all the images are cached on load
not sure what you mean.
S.a.n.4.e.s wrote: If it matter's, i can show code
it might be useful, *after* you tried to localize and fix the slow parts.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
<blockquote class="FQ"><div class="FQA">Luc Pattyn wrote:</div> S.a.n.4.e.s wrote:
i assume that all the images are cached on load
not sure what you mean.</blockquote>
I mean, that all the collection of images, binded to ListView, are loading on startup. I use a single thread, don't use network or database, i simple get *.jpg files from some directory on one of my disks.
There's my code.
XAML:
<pre>
<usercontrol.resources>
<objectdataprovider x:name="PhotosODP" x:key="MyPhotos" objecttype="{x:Type l:PhotoList}" xmlns:x="#unknown" />
<l:uritoimageconverter x:key="LocalUriToImageConverter" xmlns:x="#unknown" xmlns:l="#unknown" />
<DataTemplate DataType="{x:Type l:Photo}">
<Grid VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling">
<Border Background="#FF562100" Padding="4" BorderThickness="1">
<StackPanel Width="{Binding ElementName=Zoomer, Path=Value}" Margin="5" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling">
<Image Source="{Binding Source, Converter={StaticResource LocalUriToImageConverter}}" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling"/>
<Label Foreground="White" Content="{Binding FileName}" />
</StackPanel>
</Border>
</Grid>
</DataTemplate>
</usercontrol.resources>
</pre>
And C# class, that makes a collection:
<pre>
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Media.Imaging;
namespace Components
{
public class Photo
{
public Photo(string path)
{
_source = path;
_name = path.Substring(path.LastIndexOf("\\") + 1);
}
public override string ToString()
{
return Source;
}
private string _source;
public string Source { get { return _source; } }
//my
private string _name;
public string FileName { get { return _name; } }
//
}
public class PhotoList : ObservableCollection<photo>
{
public PhotoList() { }
public PhotoList(string path) : this(new DirectoryInfo(path)) { }
public PhotoList(DirectoryInfo directory)
{
_directory = directory;
Update();
}
public string Path
{
set
{
_directory = new DirectoryInfo(value);
Update();
}
get { return _directory.FullName; }
}
public DirectoryInfo Directory
{
set
{
_directory = value;
Update();
}
get { return _directory; }
}
private void Update()
{
foreach (FileInfo f in _directory.GetFiles("*.jpg"))
{
Add(new Photo(f.FullName));
}
}
DirectoryInfo _directory;
}
}
</photo></pre>
And an event of an app, on which load of images starts:
<pre>
private void UserControl_Initialized(object sender, EventArgs e)
{
photos = (PhotoList)(this.Resources["MyPhotos"] as ObjectDataProvider).Data;
photos.Path = path;
}
</pre>
modified on Saturday, March 14, 2009 6:57 AM
|
|
|
|
|
Hi,
I am using InkCanvas control for signature. Can anyone tell me how to store these signatures in sql server DB?
Vsaratkar
|
|
|
|
|
Save the strokes to a memory stream
var memoryStream = new System.IO.MemoryStream();
inkCanvas.Strokes.Save(memoryStream);
to compress the data
then store the data of the memory stream in your database as an appropriate binary type.
to load the data to an InkCanvans from a memory stream
inkCanvas1.Strokes = new StrokeCollection(memoryStream);
memoryStream = 0
Eslam Afifi
|
|
|
|
|
|
Glad to help
Eslam Afifi
|
|
|
|
|
I see how to store the strokes DB. We've been successful at this in storing signatures from a tablet application. I now want to be able to present our signatures via a web report. I want to be able to convert my strokes directly to a png or bitmap and display using SS Reporting Services image control. So, I need to convert the strokes collection, stored in the database, to to bitmap byte[], as we're unable to use the inkcavas control in SSRS. Does anyone know how to do this?
-Andy
|
|
|
|
|
Adventures into Ink API using WPF[^] does that. But it outputs only the visible parts of the ink. You may want to ensure that the InkCanvas or InkPresenter is big enough to contain all the ink in it.
The StrokeCollection has a method Draw[^] that draws on a DrawingContext, maybe you want to investigate that.
By the way, you should start a new thread instead of replying to an old one to increase the probability that someone see your question and someone may have a better solution.
Eslam Afifi
|
|
|
|
|
Hello.
Has anyone come across a nice, sturdy Tweening library for WPF? Coming from Flash I have been spoiled by Tweener, TweenMax, GTween etc and am in shock that MS has not provided something similar for WPF when us designers consider it an essential.
Cheers, E.
|
|
|
|
|
This Silverlight version[^] looks promising - a WPF version would be extremely simple to achieve.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys
|
|
|
|
|
Chers for that, I'll give it a whirl. I found Bling too which is mighty fun.
|
|
|
|
|
Hi
I discovered that Blender can export to the .obj format which is supported in Expression Blend, so I'll be using Blender as my 3D modeling application.
The problem I'm facing though, is loading these models onto a ViewPort whenever the user wishes to do so, and not whenever the application loads e.g. I want to create a drop down menu which displays all my models, and as soon as the user clicks on a menu item ("chair" for instance), an already created model of a chair must be loaded and displayed. Is this possible, and how?
Code samples would be helpful
Thanks in advance
|
|
|
|
|
I've used the XAML Exporter for Blender[^] instead. Basically, you export your model out as XAML, which you can then bind in using XamlReader.Load.
The first step I'd take would be to define an ObservableCollection which was populated by reading in a list of items from a particular directory that end in xaml. Then, I'd bind this to the menu which would then trigger the load.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys
|
|
|
|
|
I'm using datagrid from WPF Toolkit. And I have my owen style for column header. Here is code:
<Style x:Key="ColumnHeaderStyle" TargetType="{x:Type dg:DataGridColumnHeader}">
<Setter Property="Background" Value="{StaticResource DataGrid_Style0_Header}" />
<Setter Property="Foreground" Value="Black" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="BorderBrush" Value="#FFFFCB02" />
<Setter Property="BorderThickness" Value="0,0,1,1" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type dg:DataGridColumnHeader}">
<Border BorderBrush="{TemplateBinding dg:DataGridColumnHeader.BorderBrush}" BorderThickness="{TemplateBinding dg:DataGridColumnHeader.BorderThickness}">
<Grid Name="grContentHeader" Height="20" Background="{TemplateBinding dg:DataGridColumnHeader.Background}">
<ContentPresenter Content="{TemplateBinding dg:DataGridColumnHeader.Content}" VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}" HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}" Cursor="Hand" Margin="2,0,2,0"/>
<Path Name="UpArrow" Fill="Black" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,3,0" Visibility="Hidden">
<Path.Data>
<PathGeometry>
<PathFigure StartPoint="0,0">
<LineSegment Point="6,0"/>
<LineSegment Point="3,5"/>
<LineSegment Point="0,0"/>
</PathFigure>
</PathGeometry>
</Path.Data>
</Path>
<Path Name="DownArrow" Fill="Black" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,3,0" Visibility="Hidden">
<Path.Data>
<PathGeometry>
<PathFigure StartPoint="0,5">
<LineSegment Point="6,5"/>
<LineSegment Point="3,0"/>
<LineSegment Point="0,5"/>
</PathFigure>
</PathGeometry>
</Path.Data>
</Path>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="SortDirection" Value="Ascending">
<Setter TargetName="DownArrow" Property="Visibility" Value="Visible"/>
<Setter TargetName="UpArrow" Property="Visibility" Value="Hidden"/>
<Setter TargetName="grContentHeader" Property="Background" Value="{StaticResource DataGrid_Header_Alt0}"/>
</Trigger>
<Trigger Property="SortDirection" Value="Descending">
<Setter TargetName="DownArrow" Property="Visibility" Value="Hidden"/>
<Setter TargetName="UpArrow" Property="Visibility" Value="Visible"/>
<Setter TargetName="grContentHeader" Property="Background" Value="{StaticResource DataGrid_Header_Alt0}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Problem is, that i can't resize column.
CanUserResize="True" for column and CanUserResizeColumns="True" for datagrid don't work.
Please help
<div class="ForumMod">modified on Thursday, March 12, 2009 5:23 AM</div>
|
|
|
|
|
Did you see this Thumb controls[^] ? You don't seem to have the resizing Thumb in your Template.
|
|
|
|
|
You right. I must look for some tutorial, how to use Thumb control and implement into my code. THX lot
|
|
|
|
|
The article I mentioned has it implemented.
|
|
|
|
|