-2
NotifyCollectionChangedEventHandler命令workling不與背景worker.Event工作是:NotifyCollectionChangedEventHandler沒有與後臺工作
void MainWindowsViewModel_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
StrokesEllipse = ((StrokeCollection)sender);
using (var memoryStream = new MemoryStream())
{
StrokesEllipse.Save(memoryStream);
//convert memory stream to array
EllipseDrawing = memoryStream.ToArray();
//save the above array to say - database
}
}
我們宣佈的構造事件如下
_strokesEllipse = new StrokeCollection();
(_strokesEllipse as INotifyCollectionChanged).CollectionChanged += new NotifyCollectionChangedEventHandler(MainWindowsViewModel_CollectionChanged);
我們正在結合斯托克在背景工作者完成事件的彙集。如下
string s = GetMechanicSignature();
if (s != "")
{
EllipseDrawing = Convert.FromBase64String(s);
}
if (EllipseDrawing != null)
{
try
{
using (var memoryStream = new MemoryStream(EllipseDrawing))
{
_strokesEllipse = new StrokeCollection(memoryStream);
}
}
catch (Exception)
{
}
inkcanvas控件不顯示加載的數據。爲什麼?當我們嘗試沒有後臺工作人員,然後inkcanvas控制加載數據很好? inkcanvas XML是如下
<InkCanvas x:Name="inkCanVas" Grid.Row="0" IsEnabled="{Binding VCRSignatureModel.IsEnable,Mode=TwoWay}" Background="White" Width="700" Height="90" Margin="40,0,0,0" Strokes="{Binding StrokesEllipse,Mode=TwoWay}">
<InkCanvas.DefaultDrawingAttributes>
<DrawingAttributes Color = "Black" Width = "6" />
</InkCanvas.DefaultDrawingAttributes>
</InkCanvas>
跨線程操作是不允許的。我想這是問題。 –
您需要使用Dispatcher.Invoke在UI線程上運行代碼。 –
你能提供確切的解決方案如何調用Dispatcher.Invoke – naina