|
By default IsEditable is false. You could use a DataTrigger on the ComboBox to set it's IsEditable property to True when the Items count is 0.
e.g.,
<DataTrigger Binding="{Binding Path=Items.Count, RelativeSource={RelativeSource Self}}" Value="0">
<Setter Property = "IsEditable" Value="true"/ >
</DataTrigger>
|
|
|
|
|
I tried that, but I get this error:
'DataTrigger' object cannot be added to 'ComboBox'. Operation is not valid while ItemSource is in use. Access and modify elements with ItemsControl.ItemSource instead.
This is likely because my current Control Template combobox section looks as follows:
<ComboBox ItemsSource="{Binding Path=DistrictList,RelativeSource={RelativeSource TemplatedParent}}"></ComboBox>
So, I understand what you're suggesting, but I'm not quite sure how I should be coding the xaml to achieve that?
Also, for my own understanding, I'd appreciate an explanation from someone as to why setting the IsEditable property in my CodeBehind doesn't work.
|
|
|
|
|
I was able to get this working, but I don't quite understand why...
I created a new dependency property called MyIsEditable )and MyIsEditableProperty). I then added IsEditable="{Binding Path=MyIsEditable,RelativeSource={RelativeSource TemplatedParent}}" to the combobox in my Generic.xaml for my control.
Could someone explain why I can't use the IsEditable property on my control (inherited from ComboBox), directly?
|
|
|
|
|
Hi I am a beginner in the .Net 3.5. I am making a XBAP application and trying to declare the connection string in the app.config file. When i am using the same in my code I am receiving an unexpected error:
Cannot create instance of 'Page1' defined in assembly 'WpfBrowserApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Exception has been thrown by the target of an invocation. Error in markup file 'Page1.xaml' Line 1 Position 7.
I am using the following in the code behind:
string conn = ConfigurationSettings.AppSettings["ConnectionString"].ToString();
DataSet dsEmployees = SqlHelper.ExecuteDataset(conn, CommandType.StoredProcedure, "sp_fetchEmployees");
lstEmployees.DataContext = dsEmployees;
Kindly help as I am stuck completely
-----Have A Nice Day-----
modified on Friday, March 13, 2009 11:16 AM
|
|
|
|
|
ConfigurationSettings.AppSettings is now obsolete. See here MSDN[^]. Instead use ConfigurationManager[^]/WebConfigurationManager as recommended.
Did you debug and see on which particular line does your application fail ?
|
|
|
|
|
I am not able to use ConfigurationManager. When I type Configuration, the automatic help only shows ConfigurationSettings.
-----Have A Nice Day-----
|
|
|
|
|
I shared you a link from MSDN which has example of it's usage - again link[^]
|
|
|
|
|
I wonder why I am not able to use ConfigurationManager instead of ConfigurationSettings, although I have used the Configuration class
-----Have A Nice Day-----
|
|
|
|
|
I'm not expert in this. XBAP run in partial-trust. You should expose your database through a web service (ASP.NET, WCF, ...). You may want to take a look at ADO.NET Data Services. Or include the SqlClientPermission (or OleDp's) but in this case the application can fail to run because this elevated permission.
Eslam Afifi
|
|
|
|
|
Yes you are true. I will have to use a web service to expose the data to the web application, XBAP from the SQL Server. But, I don't understand what was the need of this. Why was this not considered in the 2005 or earlier edition?
-----Have A Nice Day-----
|
|
|
|
|
In general, Internet applications should be restricted from having direct access to critical system resources, to prevent malicious damage.
As a said before, I'm not an expert but here is what i think it might be correct. Since XBAP are client side, I think they'd use the ODBC drivers at the client. But I'm not sure why they are considered a security risk (maybe because they're unmanaged code). I wish someone explain more or correct me if I'm wrong.
Eslam Afifi
|
|
|
|
|
I think you are right. They are client side application and do not even require a web server. This is the reason that they require a intermediate web service to provide the data from the database.
-----Have A Nice Day-----
|
|
|
|
|
I wonder why data access is a security risk that they are not allowed in partial-trust.
Eslam Afifi
|
|
|
|
|
Hello.
In attempting to convert from Flash to WPF I'm going through the stages of re-working stuff which is easy to do in AS3. This latest example is proving a nightmare. So, imagine you have a set of squares...
[IMG]http://img22.imageshack.us/img22/7858/grid.png[/IMG]
You click at a random place on the screen, the 'lead' square moves there and the rest catch up one afte the other. The only way I can seem to achieve this in WPF is to use three DoubleAnimations on every square, X, Y and Angle. But this leaves me with shed loads of code instead of the 2-3 lines I'd use in AS3 (it does run much quicker though). So my question is to do this simple thing in WPF, wanting a nice smooth transition and wanting to set the duration etc how would you go about it? I thought about applying a for loop and running each one through, would that be a good way?
Regards, E.
|
|
|
|
|
Animations are rather verbose but it would be quite simple to write some helper functions to do common scenarios. These tutorials tutorials might be of some use if your familar with flash, they are for silverlight but the code should be simpler in WPF as you could use a timer or CompositionTarget instead of an empty storyboard. It shouldn't be that hard to replicate the AS3 code using procedural animation.
|
|
|
|
|
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
|
|
|
|