StrokeCollection.AddPropertyData(Guid, Object) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将一个自定义属性添加到 StrokeCollection 中。
public:
void AddPropertyData(Guid propertyDataId, System::Object ^ propertyData);
public void AddPropertyData (Guid propertyDataId, object propertyData);
member this.AddPropertyData : Guid * obj -> unit
Public Sub AddPropertyData (propertyDataId As Guid, propertyData As Object)
参数
- propertyData
- Object
此自定义属性的值。 propertyData
的类型必须是 Char、Byte、Int16、UInt16、Int32、UInt32、Int64、UInt64、Single、Double、DateTime、Boolean、String、Decimal,或这些数据类型(但不包括 String,因为不允许此数据类型)的数组。
例外
示例
以下示例演示如何添加和获取自定义属性数据。 该方法AddTimeStamp_Click
使用AddPropertyData该方法将当前时间添加到 .StrokeCollection 该方法 GetTimeStap_Click
使用 GetPropertyData 该方法从中 StrokeCollection检索时间戳。 此示例假定有一个 InkCanvas 调用 inkCanvas1
。
Guid timestamp = new Guid("12345678-9012-3456-7890-123456789012");
// Add a timestamp to the StrokeCollection.
private void AddTimestamp_Click(object sender, RoutedEventArgs e)
{
inkCanvas1.Strokes.AddPropertyData(timestamp, DateTime.Now);
}
// Get the timestamp of the StrokeCollection.
private void GetTimestamp_Click(object sender, RoutedEventArgs e)
{
if (inkCanvas1.Strokes.ContainsPropertyData(timestamp))
{
object date = inkCanvas1.Strokes.GetPropertyData(timestamp);
if (date is DateTime)
{
MessageBox.Show("This StrokeCollection's timestamp is " +
((DateTime)date).ToString());
}
}
else
{
MessageBox.Show(
"The StrokeCollection does not have a timestamp.");
}
}
Private timestamp As New Guid("12345678-9012-3456-7890-123456789012")
' Add a timestamp to the StrokeCollection.
Private Sub AddTimestamp_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
inkCanvas1.Strokes.AddPropertyData(timestamp, DateTime.Now)
End Sub
' Get the timestamp of the StrokeCollection.
Private Sub GetTimestamp_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
If inkCanvas1.Strokes.ContainsPropertyData(timestamp) Then
Dim savedDate As Object = inkCanvas1.Strokes.GetPropertyData(timestamp)
If TypeOf savedDate Is DateTime Then
MessageBox.Show("This StrokeCollection's timestamp is " & _
CType(savedDate, DateTime).ToString())
End If
Else
MessageBox.Show("The StrokeCollection does not have a timestamp.")
End If
End Sub
注解
通过此方法AddPropertyData,可以将自定义属性添加到 .StrokeCollection You can then include extra information with a StrokeCollection.