|
can u give me a easy example for WPF Gird how to bind data to the grid
|
|
|
|
|
Assuming that the following is your data class:
public class MyData : INotifyPropertyChanged
{
private event PropertyChangedEventHandler _propertyChanged;
private int _id;
private string _name;
public string Name
{
get { return _name; }
set
{
if (_name != value)
{
_name = value;
OnChanged("Name");
}
}
}
public int Id
{
get { return _id; }
set
{
if (_id != value)
{
_id = value;
OnChanged("Id");
}
}
}
public event PropertyChangedEventHandler PropertyChanged
{
add { _propertyChanged += value; }
remove { _propertyChanged -= value; }
}
private void OnChanged(string p)
{
PropertyChangedEventHandler handler = _propertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(p));
}
}
} Add an observable collection to watch this:
private ObservableCollection<MyClass> _data = new ObservableCollection<MyClass>(); Add some data to the observable collection:
_data.Add(new MyClass{Id=1, Name="Josh"}); Assign the collection to the datacontext of your window using
DataContext = _data; There you have the basics of the data. All you need do now, is bind the ItemsSource of the grid to the data source, as in:
ItemsSource="{Binding}"
"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 | Onyx
|
|
|
|
|
Ok, I shall try to explain as thoroughly as possible the problem I'm experiencing.
I have TextBox in a tab on the left of my window (Text1). The rest of the window has another TextBox (Text2). As I type into Text2, if I press F12, I grab the current word and try to put it into Text property on the TextBox Text1. Although the TextChanged event fires and I can see its Text property has been set, visually it isn't set and the code dependant on the new value runs and then 'unruns' if you follow me.
I don't know if this is a focus issue or something, but there are no exceptions in the output window and no more major breakages.
Does anyone have any idea what I might be missing here?
Thanks in advance,
Simon
|
|
|
|
|
This is a WPF project ? Do you have any events on the other textbox that might fire and change or reject the text ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Yeah, this is WPF. I know what you mean, but I don't set the Text property anywhere else or set e.Handled to true or false anywhere.
When I set the Text property, TextChanged fires on that TextBox as normal. In that handler, I read the value out to use it for other purposes. All this code does run ok, but visually, it's as if nothing happened!
This is odd. I'm going to try and create a simple WPF app with 2 TextBoxes and do something similar.
If you have any other ideas, I'd love to hear them.
|
|
|
|
|
Are you setting the text property of TextBox1, or are you updating property to which the Text property of TextBox1 is bound?
If you are updating a property the problem is likely that you need to raise an OnPropertyChanged event for that property. You'll have to implement INotifyPropertyChange...
|
|
|
|
|
Hi,
I am using binding a fair bit, but in this particular case, this textbox is not bound to anything. I am merely doing the following:
myTextBox.Text = "some text";
I am getting some bizarre feeling that WPF is preventing the visual change based on some form of focus or caret permission type thing, but I can't be convinced of this.
It's an odd one at the moment.
|
|
|
|
|
Dear all,
I have a maintenance database table(having ColA(primary) and ColB(varchar)) being records inserted using asynchronous web service.Before inserting a new record into table on save button click event,i have to check uniqueness of record.So, When i send query request to check with given record Webservice completed event is raised after the save button click event.So, I am not able to check the uniqueness using asynchronous web services.Please help me in finding a solution for this.
regards,
Sundeep G
|
|
|
|
|
I am altering my existing application developed using MS Access + VBA. I have created new window (wpf) which handles some tasks. I want this window to be loaded on button click from old MS Access application.
Is it possible to do this?
Sorry if posted at wrong forum.
|
|
|
|
|
hi guys i am using vs 2008 sp1 and i have installes silver light controls tool kit
but when i run sample solution it says gives an error stating
" type expander exsist both in control.dll and toolkit.control.dll ?
why ?
Tauseef A Khan
MCP Dotnet framework 2.0.
|
|
|
|
|
Do you have two toolkit versions installed?
The current namespace and assembly for the Expander control is
xmlns:stk="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
I would uninstall any Silverlight Dev Tools and toolkit versions
and reinstall the latest versions:
Microsoft® Silverlight™ 3 Tools for Visual Studio 2008 SP1[^]
Silverlight Toolkit[^]
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
no i just have silver light 3 tools and silver light control tool kit july 2009.
and another issue i get an error while compiling
the managed debugger package for silver light is not installed
why ?
Tauseef A Khan
MCP Dotnet framework 2.0.
|
|
|
|
|
I'm pretty sure my recommendation will fix both your issues.
When Silverlight 3 was released, I uninstalled Silverlight,
the silverlight VS tools, and the toolkit. Then I downloaded and
installed (in order) everything on the Get Started Building Silverlight 3 Applications[^]
page. Except for some namespace shuffling (they keep changing stuff for WPF
compatibility and when controls get migrated from the toolkit to the
framework) everything works correctly.
The toolkit is essentially beta, so I highly recommend keeping
up the latest version. They are fixing stuff every few months.
July is not the newest.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
I am working on a silverlight application. In this I need to access session variables in silverlight application.For this I created a WCF service to get the session variable. For this I used the following code:
In service
[ServiceContract(Namespace = "")][AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
UserId = int.Parse(System.Web.HttpContext.Current.Session["LoginUserID"].ToString());
In web.config file:
<serviceHostingEnvironment aspNetCompatibilityEnabled="true">
but I am getting the following error:
System.Reflection.TargetInvocationException: An exception occurred during the operation, making the result invalid. Check InnerException for exception details. ---> System.ServiceModel.CommunicationException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound.
If any one have any idea to solve this or directly access the session variable in silverlight application please reply me.
Thanks in advance.
|
|
|
|
|
Hi,
I am getting an exception while calling a WCF service in silver lght application.This exception is as below.
Exception:
An exception occurred during the operation, making the result invalid. Check InnerException for exception details. ---> System.InvalidOperationException: The underlying channel factory could not be created because no binding information was found in the configuration file for endpoint with name '*'. Please check the endpoint configuration section with name '*' to ensure that binding information is present and correct.
If anyone have idea to solve this please reply me.
Thanks in advance.
|
|
|
|
|
First idea is this: follow the suggestion of the exception and verify your binding information. You have to have a basicHTTPBinding in order to use WCF with Silverlight. Try Googling "Using WCF with Silverlight 3.0" and you will discover a wealth of information.
|
|
|
|
|
Hi,
I am working on a silverlight application. In this I developed a WCF service in this silverlight application itself. Now I want to use this in a silverlight page or form.
If anyone have any idea to on using a WCF application in silverlight application please reply me.
Thanks in advance.
|
|
|
|
|
Nekkantidivya wrote: If anyone have any idea to on using a WCF application in silverlight application please reply me.
Maybe you could actually reply to peoples replies instead of
asking the same question over and over.
I asked before: Are the endpoints configured properly on both ends?
From your posts, I'm thinking no.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
In addition to properly defined endpoints, you can only connect using basicHTTPBinding not wsHTTPBinding
|
|
|
|
|
Hi,
This is from Chandrakanth. Working on WPF Project.
My Problem is "HOW TO BIND THE IMAGE TO DATA GRID CONTROL FROM
DATABASE"
Actually i am getting data from DataBase to DataSet . I have to bind that Image to DataGrid Column. That Column Name is ImageDes.
Can any one tell me how to do that.
Thanks and Regards
Chandrakanth
|
|
|
|
|
What form is the image data in?
Without seeing a sample of the data class used as the DataGrid data
and what your DataGrid column definition looks like, it's difficult to
give a precise example...
Can you post a simple example of the XAML and the data class?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Dear all,
I have datagrid control being data bind from database using webservice in which there are two columns called ColA and ColB.
ColA is HyperlinkButton(DataGridTemplateColumn) and ColB is DataGridTextColumn. There is Click event for HyperlinkButton(ColA),in which I am trying get the content of both Column values(ColA and ColB).It is able to read ColA but not ColB from Code.Can anyone help me regarding this.
Regards,
Sundeep G
|
|
|
|
|
Sundeep Ganiga wrote: .It is able to read ColA but not ColB from Code.
How are you doing this?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
Can you use the Datagrid.SelectItem property to
get the data for the entire row?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|