This is a migrated thread and some comments may be shown as answers.

Bug in Selected Value Binding

5 Answers 248 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Seth
Top achievements
Rank 1
Seth asked on 10 Jun 2009, 01:47 PM
I have combo box setup as following:

<

 

basecontrols:RadComboBox x:Name="StatusComboBox" Grid.Row="0" Grid.Column="1" Margin="0,7,0,7" HorizontalAlignment="Stretch" VerticalAlignment="Center" ItemsSource="{Binding Source={StaticResource WorkOrderStatusesData}, Path=Data}" DisplayMemberPath="Value" SelectedValuePath="Key" SelectedValue="{Binding Path=AMWorkOrderStatusID, Mode=TwoWay}" ValidationPropertyName="AMWorkOrderStatusID" />


I select a value in a combo box, then in cancel button I set data context on container control to null.  I expect that the combo box would blank out, but instead, it is keeping the selected value.

Thanks,
Seth Mims

 

5 Answers, 1 is accepted

Sort by
0
Valeri Hristov
Telerik team
answered on 10 Jun 2009, 02:04 PM
Hi Seth,

This is a known bug, that has been fixed in our development builds. Unfortunately the fix is part of major functionality changes in RadComboBox (port to WPF) and will not be available until Q2 2009, scheduled for the beginning of the next month. I updated your points and I hope that the release timeframe is appropriate for you.

Regards,
Valeri Hristov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Seth
Top achievements
Rank 1
answered on 08 Jul 2009, 12:20 PM
We downloaded the newest release (Q2 updates) on July 7, 2009 and it appears as though this issue is still there.  The ComboBox was still not clearing out.

Thanks,
Seth Mims
0
Valeri Hristov
Telerik team
answered on 09 Jul 2009, 02:53 PM
Hi Seth,

I tested with the attached application and the official assemblies, version 2009.2.701.1020, and everything seems to work fine. Please, let me know if I am missing something, or if your scenario is different, please, modify my application to match it and I will provide a recommendation or bugfix.

Regards,
Valeri Hristov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Valeri Hristov
Telerik team
answered on 09 Jul 2009, 03:00 PM
Hello Seth,

I attached the wrong version of the application. Please, check this one which also seems to work as expected (after the second selection there is no data context and the button click has no effect!).

Greetings,
Valeri Hristov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Seth
Top achievements
Rank 1
answered on 10 Jul 2009, 03:00 PM

We were able to duplicate our problem by doing a little modification to your program.  Below is the code we used.  Please let me know if we can provide any additional information.  It definitely looks like there is an issue there.

Thanks,
Seth Mims



Page.xaml

 

<

 

UserControl x:Class="SilverlightApplication1.Page"

 

 

 

 

 

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

 

 

 

 

 

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

 

 

 

 

 

xmlns:local="clr-namespace:SilverlightApplication1"

 

 

 

 

 

xmlns:telerikInput="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input">

 

 

 

 

 

 

<UserControl.Resources>

 

 

 

 

 

 

<local:DataProvider x:Key="Provider" />

 

 

 

 

 

 

</UserControl.Resources>

 

 

 

 

 

 

<Grid DataContext="{Binding Source={StaticResource Provider}, Path=Data}">

 

 

 

 

 

 

<StackPanel Background="White" x:Name="LayoutRoot">

 

 

 

 

 

 

<telerikInput:RadComboBox x:Name="cmb" DataContext="{Binding}" ItemsSource="{Binding Source={StaticResource Provider}, Path=Items}"

 

 

 

 

 

SelectedValuePath="ID" SelectedValue="{Binding SelectedValue, Mode=TwoWay}"

 

 

 

 

 

DisplayMemberPath="Text" Width="200" />

 

 

 

 

 

 

<Button Content="Click me to clear SelectedValue on the DataModel" Click="Button_Click"

 

 

 

 

 

Width="100" />

 

 

 

 

 

 

<Button x:Name="StepOne" Content="Step 1" Click="StepOne_Click"

 

 

 

 

 

Width="100" />

 

 

 

 

 

 

<Button x:Name="StepTwo" Content="Problem" Click="StepTwo_Click"

 

 

 

 

 

Width="100" />

 

 

 

 

 

 

<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" >

 

 

 

 

 

 

<TextBlock Text="SelectedValue:" />

 

 

 

 

 

 

<TextBlock Text="{Binding SelectedValue}" />

 

 

 

 

 

 

</StackPanel>

 

 

 

 

 

 

</StackPanel>

 

 

 

 

 

 

</Grid>

 

</

 

UserControl>



page.xaml.cs

 

using

 

System;

 

 

 

using

 

System.Collections.Generic;

 

 

 

using

 

System.Linq;

 

 

 

using

 

System.Net;

 

 

 

using

 

System.Windows;

 

 

 

using

 

System.Windows.Controls;

 

 

 

using

 

System.Windows.Documents;

 

 

 

using

 

System.Windows.Input;

 

 

 

using

 

System.Windows.Media;

 

 

 

using

 

System.Windows.Media.Animation;

 

 

 

using

 

System.Windows.Shapes;

 

 

 

using

 

System.ComponentModel;

 

 

 

using

 

System.Collections.ObjectModel;

 

 

 

namespace

 

SilverlightApplication1

 

{

 

public partial class Page : UserControl

 

 

 

 

{

 

private DataModel DataModel;

 

 

public Page()

 

{

InitializeComponent();

 

//this.DataModel = this.Resources["DataModel"] as DataModel;

 

 

 

 

 

//this.LayoutRoot.DataContext = this.DataModel;

 

 

 

 

 

DataProvider model = this.Resources["Provider"] as DataProvider;

 

 

DataCollection collection = new DataCollection();

 

collection.Add(

new Data() { Text = "item 1", ID = "1" });

 

collection.Add(

new Data() { Text = "item 2", ID = "2" });

 

collection.Add(

new Data() { Text = "item 3", ID = "3" });

 

model.Items = collection;

}

 

private void Button_Click(object sender, RoutedEventArgs e)

 

{

 

this.LayoutRoot.DataContext = null;

 

}

 

private void StepOne_Click(object sender, RoutedEventArgs e)

 

{

 

DataProvider model = this.Resources["Provider"] as DataProvider;

 

 

//initial state

 

 

 

 

model.Data =

null;

 

 

// search

 

 

 

 

 

DataModel newModel = new DataModel();

 

newModel.SelectedValue =

"2";

 

model.Data = newModel;

}

 

private void StepTwo_Click(object sender, RoutedEventArgs e)

 

{

 

DataProvider model = this.Resources["Provider"] as DataProvider;

 

 

DataModel oldData = model.Data;

 

 

//save object

 

 

 

 

model.Data = oldData;

System.Runtime.Serialization.

DataContractSerializer ser = new System.Runtime.Serialization.DataContractSerializer(typeof(DataModel));

 

System.IO.

MemoryStream stream = new System.IO.MemoryStream();

 

ser.WriteObject(stream, oldData);

stream.Flush();

stream.Position = 0;

oldData = ser.ReadObject(stream)

as DataModel; ;

 

model.Data = oldData;

 

 

// new object

 

 

 

 

model.Data =

new DataModel();

 

}

}

 

public class DataProvider : INotifyPropertyChanged

 

 

 

 

{

 

private DataModel _dataModel;

 

 

private DataCollection _dataCollect;

 

 

public DataModel Data

 

{

 

get { return _dataModel; }

 

 

set

 

 

 

 

{

_dataModel =

value;

 

OnPropertyChanged(

"Data");

 

}

}

 

public DataCollection Items

 

{

 

get { return _dataCollect; }

 

 

set

 

 

 

 

{

_dataCollect =

value;

 

OnPropertyChanged(

"Items");

 

}

}

 

public event PropertyChangedEventHandler PropertyChanged;

 

 

private void OnPropertyChanged(string propertyName)

 

{

 

if (this.PropertyChanged != null)

 

{

 

this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));

 

}

}

}

 

public class DataModel : INotifyPropertyChanged

 

 

 

 

{

 

public DataModel()

 

{

}

 

private string selectedValue = string.Empty;

 

 

public string SelectedValue

 

{

 

get

 

 

 

 

{

 

return this.selectedValue;

 

}

 

set

 

 

 

 

{

 

if (this.selectedValue != value)

 

{

 

this.selectedValue = value;

 

 

this.OnPropertyChanged("SelectedValue");

 

}

}

}

 

public event PropertyChangedEventHandler PropertyChanged;

 

 

private void OnPropertyChanged(string propertyName)

 

{

 

if (this.PropertyChanged != null)

 

{

 

this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));

 

}

}

}

 

public class Data : INotifyPropertyChanged

 

 

 

 

{

 

private string id;

 

 

private string text;

 

 

public string ID

 

{

 

get

 

 

 

 

{

 

return this.id;

 

}

 

set

 

 

 

 

{

 

if (this.id != value)

 

{

 

this.id = value;

 

 

this.OnPropertyChanged("ID");

 

}

}

}

 

public string Text

 

{

 

get

 

 

 

 

{

 

return this.text;

 

}

 

set

 

 

 

 

{

 

if (this.text != value)

 

{

 

this.text = value;

 

 

this.OnPropertyChanged("Text");

 

}

}

}

 

public event PropertyChangedEventHandler PropertyChanged;

 

 

private void OnPropertyChanged(string propertyName)

 

{

 

if (this.PropertyChanged != null)

 

{

 

this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));

 

}

}

}

 

public class DataCollection : ObservableCollection<Data>

 

{

}

}

Tags
ComboBox
Asked by
Seth
Top achievements
Rank 1
Answers by
Valeri Hristov
Telerik team
Seth
Top achievements
Rank 1
Share this question
or