![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
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.
br>
|
|
|||||||
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 | ||
|
Guest
Posts: n/a
|
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; } } }} |
||
|
|
|
|