Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums

Go Back   Vista Forums > Vista technology newsgroups > Avalon

Bug: ItemsControl SelectedValue Binding Fails

Reply
 
Thread Tools Display Modes
Old 12-15-2007   #1
JasonMueller
Guest
 
Posts: n/a

Bug: ItemsControl SelectedValue Binding Fails

First off, a disclaimer. This is a "repost" of something that I posted at
the forums and the ensuing conversation. This looks like a bug to me but any
help would be appreciated. For an easier to read version, go to:
http://forums.microsoft.com/MSDN/Sho...83912&SiteID=1
Thanks!

Okay, given the following .cs classes and .xaml window, why does having a
RichTextBox before the ItemsControl break the SelectedValue Binding? If the
RichTextBox is removed, the ItemsControl (specifically its child ListBoxes)
get the current value of the State.FavoriteCity property and when a new value
is selected the new value is reflected on the State.FavorityCity property.



When the RichTextBox is added, however, the value binding no longer works.
Bug?



I've included all of the source necessary to repro. Just create a new WPF
Windows Application and past the XAML below into Window1.xaml and the code
into a new file (Classes.cs works fine). To verify that the property was
not getting set, I placed a watchpoint on the set { favoriteCity = value; }
line and had it output the value being set to the debug window.







Code Snippet: Window1.xaml<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:FunkyListBoxSelectedValue="clr-namespace:FunkyListBoxSelectedValue"
x:Class="FunkyListBoxSelectedValue.Window1"
Title="FunkyListBoxSelectedValue" Height="455" Width="694" >
<Window.Resources> <DataTemplate x:Key="StateListItemTemplate">
<StackPanel Width="Auto" Height="Auto"> <TextBlock
Text="{Binding Path=Name, Mode=Default}" TextWrapping="Wrap"/>
<ListBox Width="Auto" Height="Auto" DisplayMemberPath="Name"
ItemsSource="{Binding Path=Cities, Mode=Default}"
IsSynchronizedWithCurrentItem="True" SelectedValue="{Binding
Path=FavoriteCity, Mode=Default}" SelectedValuePath="Name"/> </<
SPAN>StackPanel> </< SPAN>DataTemplate>
<FunkyListBoxSelectedValue:Country x:Key="countryData" Name="USA">
<FunkyListBoxSelectedValue:Country.States>
<FunkyListBoxSelectedValue:State Name="Kentucky" FavoriteCity="Louisville">
<FunkyListBoxSelectedValue:State.Cities>
<FunkyListBoxSelectedValue:City Name="Lexington"/>
<FunkyListBoxSelectedValue:City Name="Louisville"/> </<
SPAN>FunkyListBoxSelectedValue:State.Cities> </<
SPAN>FunkyListBoxSelectedValue:State> <FunkyListBoxSelectedValue:State
Name="Washington"> <FunkyListBoxSelectedValue:State.Cities>
<FunkyListBoxSelectedValue:City Name="Seattle"/>
<FunkyListBoxSelectedValue:City Name="Spokane"/> </<
SPAN>FunkyListBoxSelectedValue:State.Cities> </<
SPAN>FunkyListBoxSelectedValue:State> <FunkyListBoxSelectedValue:State
Name="Minnesota" FavoriteCity="Duluth">
<FunkyListBoxSelectedValue:State.Cities>
<FunkyListBoxSelectedValue:City Name="Minneapolis"/>
<FunkyListBoxSelectedValue:City Name="Duluth"/> </<
SPAN>FunkyListBoxSelectedValue:State.Cities> </<
SPAN>FunkyListBoxSelectedValue:State> </<
SPAN>FunkyListBoxSelectedValue:Country.States> </<
SPAN>FunkyListBoxSelectedValue:Country> </< SPAN>Window.Resources>
<Grid> <Grid.ColumnDefinitions> <ColumnDefinition
Width="0.5*"/> <ColumnDefinition Width="0.5*"/> </<
SPAN>Grid.ColumnDefinitions> <RichTextBox Width="Auto" Height="Auto"/>
<ListBox Visibility="Collapsed" HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" Width="Auto" Height="Auto" /> <ItemsControl
DataContext="{StaticResource countryData}" HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" Width="Auto" Height="Auto" Grid.Column="1"
ItemTemplate="{DynamicResource StateListItemTemplate}" ItemsSource="{Binding
Path=States, Mode=Default}" /> </< SPAN>Grid></< SPAN>Window>

Code Snippet: Classes.csusing System;using System.Collections.Generic;using
System.Text; namespace FunkyListBoxSelectedValue{ public class Country
{ public Country() { } public Country(string name) { this.name
= name; } private string name; public string Name {
get { return name; } set { name = value; } }
private List<State> states = new List<State>(); public List<State>
States { get { return states; } set { states =
value; } } } public class State { public State() { }
public State(string name) { this.name = name; } public
State(string name, string favoriteCity) { this.name = name; this.favoriteCity
= favoriteCity; } private string name; public string Name
{ get { return name; } set { name = value; }
} private string favoriteCity; public string FavoriteCity
{ get { return favoriteCity; } set { favoriteCity =
value; } } private List<City> cities = new List<City>();
public List<City> Cities { get { return cities; }
set { cities = value; } } } public class City {
public City() { } public City(string name) {this.name = name; }
private string name; public string Name { get {
return name; } set { name = value; } } }}



  Reply With Quote

Reply

Thread Tools
Display Modes









Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Vistax64.com 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48