|
I am new in WPF application, now i am studying WPF binding
Concept, i want to full detail of DataContext. and How can handle this
Please Give Any article path or explain yourself
Donot mistake me for this silly question
Thankyou
|
|
|
|
|
|
anishkannan wrote: I am new in WPF application
Seems like you're new to newsgroup posting as well.
You'll probably get much better results using a more specific
subject line than "Any body helpme".
We could all use that as the subject line for our posted questions
but it makes it hard for the people who want to help to pick out the topics
that match their expertise.
Just a suggestion...
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I'm very new to WPF so please forgive me if I've missed something obvious.
I've built a "lookless" control that inherits ComboBox. It has three dependancy properties (CountryCode, Label, and ListByName), and a ReadOnly property of DistrictList.
Whenever CountryCode changes, the Label is changed, and the DistrictList is rebuilt. (eg. Country changes from CAN to USA, Label will change from Province to State, and the list contents will change from provinces to states). When the ListByName property changes, the items in the list will flip from names, to two character codes, or back again (eg. Ontario to ON, or ON to Ontario).
In my Generic.xaml file, the ControlTemplate uses a dockpanel that contains a label and a combobox. I've bound the label Content property to the control Label property, and I've bound the combobox ItemSource to the control DistrictList property.
So far so good... I can flip between CAN and USA, and the control flips between provinces and states.
However, I also want to support a country of "Other", and when that country is chosen, the DistrictList that gets built is empty. So after building the list, I check its Count property. If it is 0, I set IsEditable to True, else I set it to False. That way, when there are no items in the list, the user can type something in, but when there are items in the list, the user can't type something in and must select something.
Changing the ComboBox's editable state is the part I can't seem to get working.
I have subs that fire when the CountryCode and ListByName depedancy properties change. Inside those subs they call a private method called LoadDistrictList. That is the method that fills the private member variable for the DistrictList property, and that sets IsEditable to true or false.
I've obviously missed something, but I'm at a loss as to what it is I've done wrong.
|
|
|
|
|
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
|
|
|
|