Tag
속성을 사용할 수 있지만 범용 태그는 winforms 일부터 숙취입니다. 그것에 대해 읽으십시오 here. 내가 태그를 좋아하지 않는 이유는 태그가 입력되지 않았기 때문입니다.이 태그는 읽기 전용이므로 의미있는 이름이 없습니다. 대안은 다음과 같습니다
첨부 파일 속성 그것은 운이 좋게 VS는 조각 유형 propa
눌러 탭이 비와이 티, 쓰기 어렵다
.
그래서 :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Shapes;
namespace SO_AttachmentProperty
{
public sealed class EllipseAttachments
{
#region Field1
public static int GetField1(DependencyObject obj)
{
return (int)obj.GetValue(Field1Property);
}
public static void SetField1(DependencyObject obj, int value)
{
obj.SetValue(Field1Property, value);
}
// Using a DependencyProperty as the backing store for Field1. This enables animation, styling, binding, etc...
public static readonly DependencyProperty Field1Property =
DependencyProperty.RegisterAttached("Field1", typeof(int), typeof(EllipseAttachments), new UIPropertyMetadata(0));
#endregion
#region Field2
public static int GetField2(DependencyObject obj)
{
return (int)obj.GetValue(Field2Property);
}
public static void SetField2(DependencyObject obj, int value)
{
obj.SetValue(Field2Property, value);
}
// Using a DependencyProperty as the backing store for Field2. This enables animation, styling, binding, etc...
public static readonly DependencyProperty Field2Property =
DependencyProperty.RegisterAttached("Field2", typeof(int), typeof(EllipseAttachments), new UIPropertyMetadata(0));
#endregion
}
}
는 다음과 같이 속성을 사용
코드에서
var ellipse = new Ellipse();
//write
EllipseAttachments.SetField1(ellipse, 123);
EllipseAttachments.SetField2(ellipse, 456);
//read
var f1 = EllipseAttachments.GetField1(ellipse);
var f2 = EllipseAttachments.GetField2(ellipse);
첨부 파일 속성 참고 로컬 네임 스페이스 XAML에서 거기에 자신에 와서 . 이 'myValue'를 포함하지 않기 때문에
<Window x:Class="SO_AttachmentProperty.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:SO_AttachmentProperty"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Ellipse local:EllipseAttachments.Field1="789" local:EllipseAttachments.Field2="67"/>
</Grid>
</Window>
정말 정확히 문제가 무엇인지 이해가 안 ... – phil13131
ellipse.myValue는 컴파일되지 않습니다.Ellipse 클래스를 확장하여 포함 할 것이지만 봉인 된 클래스이므로 할 수 없습니다. 클릭 이벤트에 대한 추가 정보 (myValue)가 필요합니다. – csomakk
@csomakk : [첨부 된 속성] (http://msdn.microsoft.com/en-us/library/ms749011.aspx)을 찾고 있습니다. – user7116