Welcome to Windows Presentation Foundation (WPF)
Top Tasks :

WPF Team Bloggers

Browse by Tags

All Tags » Data Binding   (RSS)

  • Databinding and Add-Ins

    There are many advantages to using the .NET Framework add-in technology to factor application logic and UI, including security isolation, discovery, activation, communication, lifetime management, and versioning. WPF builds on the .NET Framework add-in technology to enable visual add-ins ie add-ins that provide UI for host applications to display. All that you need to do is define the contract to specify what types of things the host wants the add-in's UI to do. The end result for the user is that they see both host and add-in UI intermingled without knowing about the complex machinery underneath to make it work. And, to some degree, developers might approach the development of add-ins the same way. For example, when a WPF host application displays a UI provided by an add-in, developers might intuitively expect features like data binding, commanding etc to just work. Features like this, though, need a little extra work to, err, get working because features like these weren't originally Read More...
  • Data Validation in 3.5

    A cool new feature in the Data area in 3.5 is the support for IDataErrorInfo. Let's take a look at the data validation model in 3.5 by starting with a memory refresher of that in 3.0. We end with a section that discusses how to choose between the different approaches. 3.0 Validation Model In 3.0, you would create a custom ValidationRule or use the built-in ExceptionValidationRule this way: < Binding Source ="{ StaticResource data }" Path ="Age" UpdateSourceTrigger ="PropertyChanged"> < Binding.ValidationRules > < ExceptionValidationRule /> </ Binding.ValidationRules > </ Binding > If the ExceptionValidationRule has been associated with the binding and there’s an exception when the binding engine attempts to set the property on the source, then the binding engine creates a ValidationError with the exception and adds it to the Validation.Errors collection of the bound element. You can use the errors in the collection to provide additional visual feedback (in Read More...
  • Expert advice on XmlDataProvider usage

    I came across the following Q&A from the technical chat transcript from several months ago. Our WPF data binding expert Sam Bent was the one providing the great answers. It’s excellent information about the XmlDataProvider and I thought I’d share it here. Q: What are the guidelines for using XmlDataProvider for Xml binding? Setting the data context directly on a control such as a list box seems to work. A: That works fine for one-shot use. XDP is useful if: 1. you want to switch the source to a different XML file 2. you want to pre-filter the XML via an XPath query 3. it automatically reads the XML on a background thread - avoids blocking the UI 4. it gives a convenient place to share the data among several controls 5. it gives a convenient place to assign the XmlNamespaceManager (if your XML uses namespaces) If you don't need any of this, you can skip XDP . Q: So two way binding utilizing the XmlDataProvider only works between the target and the "in memory" XML? Is there a way without Read More...
  • Binding to Web Services

    In WPF, you bind to objects returned by web service method calls the same way you bind to any other objects. To demonstrate, we’ll walk through a simple application that consumes the MSDN/TechNet Publishing System (MTPS) Content Service, discussed here . Our application implements a very simple scenario that retrieves the list of languages supported by a given document. Create a Reference to the Web Service The first step is to create a reference to the MTPS web service. To create a web reference using Visual Studio: Open your project in Visual Studio . From the Project menu, click Add Web Reference . In the dialog box, set the URL to the following: http://services.msdn.microsoft.com/contentservices/contentservice.asmx?wsdl Press Go , then Add Reference , to create the web reference. Call the Web Service and Set the DataContext We are now ready to call the GetContent web service method and bind to the returned object. All we need to do is call the web service and set the DataContext property Read More...
  • How do I programmatically interact with template-generated elements? Part II

    This post shows you how to find a named element within a DataTemplate. In Part I , we discussed how to find a named element within a ControlTemplate. That was fairly simple; you’d call Template.FindName on the control that the ControlTemplate has been applied to. But if the template is a DataTemplate, then the scenario is a bit more complex. For instance, if you have a data-bound ListBox that uses a DataTemplate, each generated list item has a tree of generated elements (as described by your DataTemplate). In this post, we’ll walk through that scenario and retrieve a named element within the DataTemplate of a certain list item. Before showing the code that finds the named element, let’s set up our scenario. We have a Button and a ListBox that’s data-bound (if you want to see how this particular ListBox is bound, you can download the attached zip file). < Border Margin = " 15 " BorderBrush = " Aqua " BorderThickness = " 2 " Padding = " 8 " CornerRadius = " 5 " > < StackPanel > Read More...
  • Displaying Enum Values using Data Binding

    Some of the FAQs about data binding are: • How do I bind to a method? • How do I bind between instantiated controls? • How do I bind an ItemsControl to an enum? I put together a quick sample that should answer the above questions: < Window xmlns =...( read more ) Read More...

Copyright © 2006 Microsoft Corporation. All Rights Reserved. | Terms of Use | Privacy Statement | Contact Us