Note that there are some explanatory texts on larger screens.

plurals
  1. POReferencing controls in a WPF DataTemplate
    primarykey
    data
    text
    <p>In a WPF page that I'm designing for my church, I have two ListBox controls bound to the results of two Linq-to-Entities queries: the first listbox/query contains all the folks who haven't yet pledged for the year, the second listbox/query contains all the folks who have pledged (and their associated pledges). Specifically:</p> <pre><code>var familiesWithNoPledges = from family in entities.Family.Include("Pledge") where !family.Pledge.Where(p =&gt; p.PledgeYearID == pledgeYear).Any() select family; var familiesWithPledges = from family in entities.Family join pledge in entities.Pledge.Include("PledgeFrequency").Where(p =&gt; p.PledgeYearID == pledgeYear) on family equals pledge.Family select new { family, pledge }; </code></pre> <p>When the user of the application selects a family from the first ListBox, the ListBox item expands slightly to show the fields for a pledge, so that it's easy to add the pledge details to the second ListBox. It looks something like this:</p> <p><a href="http://wouldbetheologian.com/images/PledgeManager.jpg" rel="nofollow noreferrer">http://wouldbetheologian.com/images/PledgeManager.jpg</a> <a href="http://wouldbetheologian.com/images/PledgeManager.jpg" rel="nofollow noreferrer">(Offsite Image)</a></p> <p>The underlying database (among other things) has a "Family" table with a 1:many relationship to a "Pledge" table. And when the user clicks the "Add Pledge" button, I'd like to create the new Pledge instance, save it to the database, and then refresh the two controls.</p> <p>But I can't figure out how to do that. If I try to do it in the code-behind, it doesn't seem like the event handler for the (n-instances of the) "Add Pledge" button can reference the controls in question; and in XAML, if I try to bind the ListBoxItem DataTemplate controls to the Family.Pledge (or Family.Pledge.FirstOrDefault()) fields, those fields are still empty when I look at the current Family object in the event handler for the Add Pledge button.</p> <p>Any thoughts on how to solve this? Or is there a better UI model I should look at altogether?</p> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload