Salem to All.
I am working on a light switch application and i am using control from a silverlight class library, i did build a user control in silverlight with is a listbox item container style of it is composed of listbox and textblock. this is my XAML code:
<UserControl.Resources>
<Style x:Key="BedsStyle" TargetType="ListBoxItem">
<Setter Property="Margin" Value="2" />
<Setter Property="Template" >
<Setter.Value>
<ControlTemplate>
<StackPanel Orientation="Vertical" Background="#FF7F98EC" Width="350" Height="130">
<StackPanel.Triggers>
</StackPanel.Triggers>
<StackPanel Orientation="Horizontal" >
<TextBlock Text="301-P" Margin="5,0,0,0" Width="175"/>
<TextBlock Text="5" Width="25" HorizontalAlignment="Right" Margin="55,0,0,0"/>
<TextBlock Text="A" Width="25" HorizontalAlignment="Right"/>
<TextBlock Text="30/7/2013" Width="100" HorizontalAlignment="Right"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Image Source="http://127.0.0.1/WordIcons/2.jpg" Width="100" Margin="5,0,0,0"/>
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal" Margin="5,5,0,5">
<TextBlock Text="JOHM filip Albert" Width="120" HorizontalAlignment="Right"/>
<TextBlock Text="Dr. Farid Najjar" HorizontalAlignment="Right"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="5,5,0,5">
<TextBlock Text="32 years old" Width="120" HorizontalAlignment="Right"/>
<TextBlock Text="Douleur torasique bla bla bla " Width="120" HorizontalAlignment="Right" TextWrapping="Wrap" Height="75"/>
</StackPanel>
</StackPanel>
</StackPanel>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="RoomsStyle" TargetType="ListBoxItem">
<Setter Property="Margin" Value="10" />
<Setter Property="Template" >
<Setter.Value>
<ControlTemplate>
<StackPanel Orientation="Vertical">
<ListBox BorderBrush="Transparent" ItemsSource="{Binding MedicationUnitRoomBeds}">
<ListBox.ItemTemplate>
<DataTemplate>
<local:BedStyleSelector Content="{Binding Stage}">
<local:BedStyleSelector.Occuped >
<DataTemplate >
<Grid Background="Gray" Width="150" Height="50"/>
</DataTemplate>
</local:BedStyleSelector.Occuped>
<local:BedStyleSelector.Ready >
<DataTemplate >
<Grid Background="Green" Width="150" Height="50"/>
</DataTemplate>
</local:BedStyleSelector.Ready>
<local:BedStyleSelector.Cleaning >
<DataTemplate >
<Grid Background="Yellow" Width="150" Height="50"/>
</DataTemplate>
</local:BedStyleSelector.Cleaning >
<local:BedStyleSelector.Stoped >
<DataTemplate >
<Grid Background="Red" Width="150" Height="50"/>
</DataTemplate>
</local:BedStyleSelector.Stoped>
</local:BedStyleSelector>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,3,0,0" Text="{Binding Room1.Code}"/>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White">
<ListBox ItemContainerStyle="{StaticResource RoomsStyle}" Width="1750" Height="880" ItemsSource="{Binding Screen.MedicationUnitRooms}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel Width="1730" Height="850"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</Grid>
when I Run the solution and open the screen that use this control this message appear :
Exception has been thrown by the target of an invocation.
{System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: It is not valid to execute the operation on the current thread.
at Microsoft.LightSwitch.Threading.DispatcherExtensions.VerifyAccess(IDispatcher dispatcher)
at Microsoft.LightSwitch.Framework.Internal.EntityCollection`3.GetEnumerator()
at Microsoft.LightSwitch.Framework.EntityCollection`1.System.Collections.IEnumerable.GetEnumerator()
at System.Windows.Controls.ItemCollection.EnumerableCollectionView.InitializeSnapshot()
at System.Windows.Controls.ItemCollection.UpdateItemsSourceList(IEnumerable newItemsSource)
at System.Windows.Controls.ItemsControl.ItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)
at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
at System.Windows.DependencyObject.RefreshExpression(DependencyProperty dp)
at System.Windows.Data.BindingExpression.SendDataToTarget()
at System.Windows.Data.BindingExpression.SourceAcquired()
at System.Windows.Data.Debugging.BindingBreakPoint.<>c__DisplayClass4.<breakonsharedtype>b__3()
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at System.Delegate.DynamicInvoke(Object[] args)
at Bedsxaml_2.BindingOperation(Object BindingState, Int32 , Action ) in SilverlightControls\Beds\Control\Beds.xaml:line 55}
in line 55 I Have this :
<listbox borderbrush="Transparent" itemssource="{Binding MedicationUnitRoomBeds}">can any one help me to find and solve this problem.
and thanks for all.