I have a Listbox with a datatemplate:
<
DataTemplate
x:Key
=
"ListBoxDataTemplate"
>
<
StackPanel
Orientation
=
"Horizontal"
>
<
TextBlock
Text
=
"{Binding FieldName, Mode=TwoWay}"
Width
=
"120"
/>
<
telerik:RadAutoCompleteBox
Width
=
"197"
Name
=
"autoCompBox"
Background
=
"Beige"
SelectionMode
=
"Multiple"
TextSearchMode
=
"StartsWith"
TextSearchPath
=
"Code"
AutoCompleteMode
=
"Suggest"
DropDownItemTemplate
=
"{StaticResource ContactSearchTemplate}"
DataContext
=
"{Binding}"
ItemsSource
=
"{Binding DataContext.Codes, Mode=TwoWay, RelativeSource={RelativeSource AncestorType=telerik:RadListBox}}"
SelectedItems
=
"{Binding Path=AssociatedCodes, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
>
</
telerik:RadAutoCompleteBox
>
</
StackPanel
>
</
DataTemplate
>
public
List<ReportDataAssociation> ReportDataAssociation
{
get
{
return
m_reportDataAssociation; }
set
{ m_reportDataAssociation = value; OnPropertyChanged(
"ReportDataAssociation"
); }
}
This property is an object with the following properties:
string
FieldName;
ObservableCollection<ReportCodes> AssociatedCodes;
The AssociatedCodes is binded to the SelectedItemsProperty of each AutoCompleteBox.
I load an ObservableCollection<ReportCodes> named Codes which is binded to all AutoCompleteBoxes.
The AssociatedCodes is a property of ReportDataAssociation which is binded to SelectedItems.
Any ReportCode I add to the AssociatedCodes' List is from the ObservableCollection<ReportCodes> named Codes
so the referece to the object is the same.
The problem is:
When I select or delete some items from some autocompletebox,
the property AssociatedCodes does not change.
When I change the property AssociatedCodes at runtime, the selectedItems in autocompletebox
don't change.
I think it's a binding problem but i can't figure out what it is.
Maybe because the AutoCompleteBoxes are in a template.
I tried to bind the selectedItems in many ways, the binding shown above is one of my many tries..
Please help
Thanx in advance
18 Answers, 1 is accepted
We investigated this and found out it was an issue with RadAutoCompleteBox. The issue appears only when the control is placed in DataTemplate in ItemsControl. A fix for it should be available in the next couple of weeks.
Thank you for your great feedback!
Greetings,
Ivo
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
I had to change the MVVM concept for this form in particular.
Let me know when the fix is avaiable.
Greetings,
Marcelo Bateira
The fix for this should be included into the latest internal build. It would be great if you test it and confirm that it is fixed on your side.
Greetings,
Ivo
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
when the build is done, as soon as I can I'll test it
Marcelo Bateira
I encountered with the same issue. Is this fix already available?
If not please help with a different solution in the meanwhile.
Thanks.
I bypass the issue using blend.
in the XAML:
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding SelectionChangedCommand}"
CommandParameter="{Binding SelectedItems, ElementName=elementsCompleteBox}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
and in the VM:
public ICommand SelectionChangedCommand { get; set; }
SelectionChangedCommand = new DelegateCommand<ObservableCollection<object>>(UpdateMultiSelect);
private void UpdateMultiSelect(ObservableCollection<object> objects)
{
myModelListSelected = new ObservableCollection<myModel>(objects.Cast<myModel>());
}
Can you specify what version do you use? A fix for this issue was included into the Q1 SP1 2013 version of RadControls for WPF.
Regards,
Ivo
Telerik
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
I'm using V 2013.1.403.40.
my code is in a DataTemplate resides in a ContentControl.
Thanks,
Hadar.
It seems we introduced this issue once again after it was fixed. A fix for this issue would be available for the first internal build after the Q2 release.
Regards,
Ivo
Telerik
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
has this issue been fixed?
I'm using RadControls_for_WPF_2013_2_1007_DEV_hotfix and the issue seems to still exist.
Thanks,
Olivier.
We did not manage to reproduce the issue with the latest internal build, could you please send us a sample project demonstrating the exact problem you're experiencing? You should open a support ticket and attach it there.
Thanks in advance
Regards,
Yana
Telerik
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Hi,
I am using version 2016.2.613.45 and the issue is still there.
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=SelectedItems; DataItem='RadAutoCompleteBox' (Name=''); target element is 'AddItemAdapterCollection' (HashCode=3396431); target property is 'Source' (type 'IEnumerable')
Any hope to get this fixed anytime?
Thanks,
Stefan
I'd ask you to open a support ticket and send us a simple project showing the exact scenario you have, so we to be able to reproduce the error and provide proper assistance.
Thank you in advance.
Regards,
Yana
Telerik by Progress
Hi Yana,
it was not my intention to become a Telerik Bug-Expert. Since this is a very basic scenario i'm sure you will find someone who will agree to code a repro for you.
Environment:
- Visual Studio 2015 with Update 3
- .NET 4.5
- Telerik WPF Controls 2016.2.613.45.NoXaml
Conditions:
- RadAutoCompleteBox was placed inside a TabControl
- SelectedItems Binding to an ObservableCollection<object>
As soon as you switch tabs and come back to the tab where the RadAutoCompletBox is located the VS debug out will show the error.
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=SelectedItems; DataItem='RadAutoCompleteBox' (Name=''); target element is 'AddItemAdapterCollection' (HashCode=19355258); target property is 'Source' (type 'IEnumerable')
Thanks,
Stefan
I am sorry for my misunderstanding.
Actually this is a known error related to a timing issue in WPF platform. More information can be found in the official social MSDN forums here: http://social.msdn.microsoft.com/Forums/vstudio/en-US/564e7160-df70-4e95-945d-60954dd7a2ae/wpf-binding-errors-systemwindowsdata-error-4?forum=wpf
Such issues should be ignored as they are timing issues in the WPF platform itself and are not critical for runtime. If you would like not to see them in the output after building your project you could use the following workaround:
- In your project's code behind set the DataBindingSource.Switch.Level to Critical. The next code snippet shows the described workaround:
System.Diagnostics.PresentationTraceSources.DataBindingSource.Switch.Level = System.Diagnostics.SourceLevels.Critical;
You could also set IsContentPreserved property of RadTabControl to true, so that the content is not reloaded every time you switch the tabs.
Regards,
Yana
Telerik by Progress
Hello Yana,
thanks for your reply.
However, if this would be a timing issue the RadAutoCompleteBox is even more broken as the control is fully rendered and no items are changed. So what does RadAutoCompletBox do? Does it refresh item lists on getting focus? I hope not! Are you sure you are handling UI rendering correctly?
Thanks,
Stefan
just to mention: I'm not using the RadTabcontrol. It's the standard WPF TabControl.
Thanks,
Stefan
Again, I apologize for the confusion.
The observed behavior is reproducible when the AutoCompleteBox is placed inside the native WPF TabControl. The control is reloading its content each time when the tabs are switching. Because of that the elements from the previously selected tab get removed from the Visual Tree and the one from the newly selected are loaded - the observed error is a timing issue that gets resolved.
What we could suggest you is instead of using the native WPF TabControl to use the one provided by Telerik RadTabControl. It provides a property named IsContentPreserved that by setting it to True prevents the controls from removing from the Visual Tree when switching between the Tabs and the bindings are preserved.
Regards,
Yana
Telerik by Progress