Monthly Archives: February 2012

Invalid cross-thread access in silverlight

Now when I receive DataServicesQuery.EndExecute and use this to pupulate a list that is bound to a usercontrol via a view model I get: “System.UnauthorizedAccessException: Invalid cross-thread access”

this error also heppend in silverlight application when you create user control or after fill list<myobj> and pass to griddate or radgridview( Telerick) control.

but here is suggests the following fix:


() =>{
CustomersGrid.ItemsSource = nwContext.EndExecute<Customers>(asResult).ToList();


Also use like………


You can change the code above so that the query executes on the UI thread by using the Deployment.Current.Dispatcher object.


() =>{




Leave a comment

Posted by on February 24, 2012 in Silverlight


Tags: , , , , , , ,

How to set control Height Width Auto in silverlight

You need to use your code like this:

MyComponent.Width = double.NaN;

suppose you have a rectangle as your object named rect

rect.SetValue(Rectangle.HeightProperty, Double.NaN);

suppose you have a grid as your object named mygrid

mygrid.SetValue(Grid.HeightProperty, Double.NaN);


your place this where you reset height or Initialize or page_load event like

  public  CallerInfo()
Loaded += new RoutedEventHandler(Page_Loaded);


void Page_Loaded(object sender, RoutedEventArgs e)
myGrid.SetValue(Grid.HeightProperty, Double.NaN);
rect.SetValue(Rectangle.HeightProperty, Double.NaN);




rec.SetValue(Rectangle.HeightProperty,”Auto”); not worked

its giving me error “DependencyProperty of type System.Double cannot be set on an object of type System.String”.

1 Comment

Posted by on February 15, 2012 in Silverlight


Tags: ,

how to disable Silverlight ScrollBar Visibility

Hi dear.

if you want to disable scrollbar from codebehind then use this code ……..

<ScrollViewer VerticalScrollBarVisibility=”Auto” HorizontalScrollBarVisibility=”Auto” IsHitTestVisible=”True” x:Name=”sviewer”>

///Write Grid Control here


sviewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
sviewer.VerticalScrollBarVisibility = ScrollBarVisibility.Disabled;


Leave a comment

Posted by on February 15, 2012 in Silverlight


Tags: , , , ,

Find control inside silverlight

There is no other way to finding a control inside a Silverlight page or controls. You need to traverse the container (Grid) element. this is a generic function that can find any type of control in side a container(Grid) control using recursion.

public T FindControl(UIElement parent, Type targetType, string ControlName) where T : FrameworkElement

if (parent == null) return null;

if (parent.GetType() == targetType && ((T)parent).Name == ControlName)
return (T)parent;
T result = null;
int count = VisualTreeHelper.GetChildrenCount(parent);
for (int i = 0; i < count; i++)
UIElement child = (UIElement)VisualTreeHelper.GetChild(parent, i);

if (FindControl(child, targetType, ControlName) != null)
result = FindControl(child, targetType, ControlName);
return result;



parent: is the container control that needs to be traversed for the desired control like grid.
targetType: Target Control type.
ControlName: is the name/Id of the control to be searched for.


how to call this function like here
TextBlock ControlToSearch = FindControl<TextBlock>((UIElement)ContainerControl, typeof(TextBlock), “NameOfTheControl”);


for (int k = 1; k <= TotalCountCbo; k++) {

RadComboBox ControlToSearch = FindControl<RadComboBox>((UIElement)myGrid, typeof(RadComboBox), “cboname” + k);


Method will return the desired control if found in container otherwise NULL.

Leave a comment

Posted by on February 6, 2012 in Silverlight


Tags: , , , , , ,