Hi,
In my application, I open a modal window in a separate thread with following method:
In this window i navigate some user controls. One of that user controls contains a RadGridView binded to an ObservableCollection. When I add an item to ObservableCollection the grid items are properly notified, but when I try to remove an item from ObservableCollection i receive
The calling thread cannot access this object because a different thread owns it.
If try to change the RadGridView with native DataGrid and all works correctly. I tried also with Dispatcher.Invoke but this approach not solve my problem.
Thanks in advance for Help.
In my application, I open a modal window in a separate thread with following method:
public
static
void
ShowInSeparateThread(Type windContent,
string
windowTitle,
int
width = 900,
int
height = 700)
{
var _viewerThread =
new
Thread(
delegate
()
{
var _eventAggregg = ServiceLocator.Current.GetInstance<IEventAggregator>();
_eventAggregg.GetEvent<ShowModalPopUp>().Publish(
true
);
var _win =
new
Window
{
Title = windowTitle,
DataContext =
new
WindowDataContext(),
WindowStartupLocation = WindowStartupLocation.CenterScreen,
WindowStyle = WindowStyle.None,
Style = Application.Current.FindResource(
"PopUpWindowStyle"
)
as
Style,
Padding =
new
Thickness(0),
Margin =
new
Thickness(0),
ResizeMode = ResizeMode.NoResize,
Content = ServiceLocator.Current.GetInstance(windContent),
Width = width,
Height = height,
ShowInTaskbar =
false
};
typeof
(Window)
.InvokeMember(
"_ownerHandle"
,
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetField,
null
, _win,
new
object
[] { Process.GetCurrentProcess().MainWindowHandle });
_win.ShowDialog();
_eventAggregg.GetEvent<ShowModalPopUp>().Publish(
false
);
})
{
IsBackground =
true
};
_viewerThread.SetApartmentState(ApartmentState.STA);
_viewerThread.Start();
}
}
In this window i navigate some user controls. One of that user controls contains a RadGridView binded to an ObservableCollection. When I add an item to ObservableCollection the grid items are properly notified, but when I try to remove an item from ObservableCollection i receive
The calling thread cannot access this object because a different thread owns it.
If try to change the RadGridView with native DataGrid and all works correctly. I tried also with Dispatcher.Invoke but this approach not solve my problem.
Thanks in advance for Help.