110,533
社区成员
发帖
与我相关
我的任务
分享
<InkCanvas x:Name="inkCanv" Margin="10" Background="White" Strokes="{Binding Strokes,Mode=TwoWay}" z:StrokeCollected.Command="{Binding OnSaveInkStroke}" z:StrokeErased.Command="{Binding OnSaveInkStroke}" z:StrokeErasing.Command="{Binding OnSaveInkStroke}">
</InkCanvas>
/// <summary>
/// 白板内容
/// </summary>
public StrokeCollection Strokes
{
get { return strokes; }
set
{
strokes = value;
this.RaisePropertyChanged("Strokes");
}
}
public ICommand OnSaveInkStroke { get; set; }
public void SaveInkStroke(EventArgs e)
{
try
{
System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
this.Strokes.Save(memoryStream);
memoryStream.Flush();
Service.ServiceClient.Instance.SendInkStrokes(memoryStream.GetBuffer());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, Title);
}
}
<Border Name="brInkCanvas" Grid.Column="1" Grid.Row="1" Visibility="{Binding IsLogin,Converter={StaticResource VisibilityConverter}}">
<InkCanvas x:Name="inkCanv" Margin="10" Background="White" Strokes="{Binding Strokes}" z:StrokeCollected.Command="{Binding OnSaveInkStroke}" z:StrokeErased.Command="{Binding OnSaveInkStroke}" z:StrokeErasing.Command="{Binding OnSaveInkStroke}">
</InkCanvas>
</Border>
/// <summary>
/// 绑定事件
/// </summary>
void BindEvent()
{
this.OnSendInkStroke = new DelegateCommand<System.Windows.Controls.InkCanvasStrokeErasingEventArgs>(SendInkStroke);
}
/// <summary>
/// 发送白板内容更新
/// </summary>
public ICommand OnSendInkStroke { get; set; }
public void SendInkStroke(System.Windows.Controls.InkCanvasStrokeErasingEventArgs e)
{
try
{
System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
this.Strokes.Save(memoryStream);
memoryStream.Flush();
Service.ServiceClient.Instance.SendInkStrokes(memoryStream.GetBuffer());
}
catch (Exception exc)
{
MessageBox.Show(exc.Message, Title);
}
}
哪里出问题了
谢谢
private StrokeCollection strokes;
/// <summary>
/// 白板内容
/// </summary>
public StrokeCollection Strokes
{
get
{
if (strokes == null)
{
strokes = new StrokeCollection();
}
return strokes;
}
}
因为没有set,前台要去掉TwoWay(注意这是集合属性,双向绑定的机制是在集合内部,而不是集合本身)
<InkCanvas x:Name="inkCanv" Margin="10" Background="White"
Strokes="{Binding Strokes}"
z:StrokeCollected.Command="{Binding OnSaveInkStroke}"
z:StrokeErased.Command="{Binding OnSaveInkStroke}"
z:StrokeErasing.Command="{Binding OnSaveInkStroke}">
</InkCanvas>
public StrokeCollection Strokes
{
get { return strokes; }
set
{ strokes = value;
this.RaisePropertyChanged("Strokes");
}
}
这时取到的就有可能不是你刚才赋的那个值。这个我也是最近刚在项目中发现的。