databinding

Best practice for User Control Data Binding - How to achieve this?

Hi folks, I've got an User Control with TextBoxes, Labels, ... . Now I would like to get the same Data Binding Features like I would place the Controls directly on the Form. I tried with an extra Binding Source and Error Provider in the User Control and I tried to make the Properties of my Controls available as an property. Nothing wor...

changing textblock to textbox loses data bindings -

this is a wpf/c# app - I have one grid where I used text boxes and the data bindings were fine. I later built another grid using textblocks. both worked well. but when I changed the textblocks in the second grid into textboxes, all but one stopped displaying data. I copied both the c# LINQ code and the XAML code that provide the data f...

Bind Collection to StackPanel

I want to take a collection of objects and bind it to a StackPanel so basically if the collection has 4 elements, inside the stack panel that should produce 4 buttons lets say. I tried this...But I dont think its the correct approach anyway. I used DataTemplated to do this type of idea in the past.. please correct me if I am wrong. Her...

What are pros and cons of using binding instead of template language?

Hello, all, I would like to know what are pros and cons of using JSON or XML binding versus using template languages like Velocity or FreeMaker? What approach is certainly preferable in what situations? ...

Interview Question

I was recently asked a weird question in an interview here it is; Private Function sorttable (ByVal dt As DataTable, ByVal sorttype$, ByVal sort_direction$) As DataTable Dim dv As DataView Dim dt2 As DataTable dt2 = dt.Clone dt2.Merge(dt) dv = dt2.DefaultView dv.Sort = so...

Binding a CollectionViewSource within a DataTemplate

'ContentTemplate' is a DataTemplate that displays an object which has a member 'FooList' (an ObservableCollection). <DataTemplate x:Key="ContentTemplate"> <ListBox ItemsSource="{Binding Path=FOO}"> ... </ListBox> </DataTemplate> I need to be able to filter that FooList using a CollectionViewSource. This is usually been...

How can one place DataBinding inline code inside of inline c# code?

How can I achieve the desired effect? Here's the code: <% if(!String.IsNullOrEmpty(%><%#Eval(Container.DataItem,"OrderXml");%><%)){ %> etc., which is placed inside of an ItemTemplate inside of a TemplateColumn. In the CodeBehind page I will bind a value to the OrderXml field, which occasionally is NULL. Unfortunately I get compi...

Binding MenuItem property (IsEnabled) to combobox property (SelectedIndex) in same control

Hey all, I've spent a good portion of my day researching this; I'm curious if it's possible to do simple binding fully in XAML, without the need to implement INotifyPropertyChanged in the code behind. Ironically, in the amount of time I've spent researching this I could have just done it in the code behind 5 times over. I've come acro...

Errors found by Bindingsource prevent form from closing

This is a winform C# problem. I have an data object, say, Person. It has a property called Age and if Age is set to a negative value an exception will be thrown from its property setter. On the form, the Age property is bound to a textbox using: var binding = tbAge.DataBindings.Add("Text", person, "Age", true, DataSourceUpdateMode.OnV...

Add editing to MVVM in a hierarchical data structure

This question is a follow-up of this older one, and it's more of a confirmation than an open question. My ViewModel instance has a private instance of the Model, _modelInst. The ViewModel has exclusive access to the Model's data during editing (so the Model doesn't need to implement INotifyPropertyChanged). Now there are three ways I c...

Displaying data objects mapped by ID elegantly in views

I have a bunch of support Cases and Users. Each Case is assigned to a User with a unique ID. My data model represents this with an AssignedUser user ID reference. This is easy to store and retrieve, but not convenient to display. When I want to display a list of Cases, the user property should be formatted as the user's username and not...

How do I bind a generic window to an arbitrary view model at runtime, using DataTemplates?

I have a large number of ViewModel classes. For each of these classes, there is a corresponding .xaml file which is a 'UserControl'. In my App.xaml, I have them registered as DataTemplates, like so: <DataTemplate DataType="{x:Type viewModel:MainMenuViewModel}"> <view:MainMenuView/> </DataTemplate> With the idea being that WPF w...

JFace - How to correctly bind a TableViewer ?

Hello all, I use the org.eclipse.core.databinding.* framework to bind some Text fields in an SWT application. I add an update strategy to validate the data and to set the value on the model only when the user click on the save button : UpdateValueStrategy toModel = new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT); if...

Binding a UIElement's Name

Is there any way to use binding to set the UIElement's name? I always get a runtime exception saying System.Windows.Markup.XamlParseException: AG_E_UNKNOWN_ERROR <Button Name="{Binding myName}" Content="{Binding myName, Mode=TwoWay}" /> If I take the binding off for the Name property the control works and the Content property is bin...

How can I unit test a WPF StyleSelector?

I'm having trouble figuring out a way to unit test a WPF style selector. My selector looks like: public class ListViewItemStyleSelector : StyleSelector { public override Style SelectStyle(object item, DependencyObject container) { var listView = ItemsControl.ItemsControlFromItemContainer(container) as ListView; ...

Silverlight Windows Phone Databinding -- noob question

I have a basic Windows Phone List application, with code like this in the MainViewModel class // CODE THAT WORKS -- Items.Clear(); foreach (var itm in e.Result) Items.Add(itm); Count = Items.Count; // CODE THAT DOES NOT WORK -- I'm trying to understand WHY Items = e.Result; The databinding Xaml looks like this: <DataTemplate...

Asp.net can i databind to fields instead of properties?

Hi All, I'm getting a List back from a WCF service and I want to set it to be the datasource for a grid. When I databind I get the error that "Deviceheader" is not a property of someObject. <td><%# Eval("Deviceheader.DeviceID") %></td> That is true, it's not a property, it's a public field public class someObject(){ public Devic...

TextBox Control wont update source through databinding

I'm trying to do a simple Databinding between a string property of an object instance, and a TextBox control. The string property has both get and set accessors, yet the source object does not implement INotifyProperty changed. This does not matter though as I'm not concerned with the object updating the text, but rather only changes to ...

asp.net formview 2 way databind null values

Hi all, I have a formview that is bound to an object data source. The object that is it bound to has certain nullable fields such as dates etc. When the textbox that the user enters the date is empty if I do not intercept the formviews iteminserting/updating events and change the e.NewValues["datefield"] to null then the datasource get...

Silverlight binding to an object contained in a list

I am trying with difficulty to use binding on an object which is contained in a list, so for example: Class A { IList<Class B> Items; } Class B { string name; } I want to have in xaml for example <Textblock Text="{Binding ClassA.Items[5].name}"/> So any ideas? much appreciated ...