ฉันกำลังพัฒนาการควบคุมแบบกำหนดเองที่ได้มาจาก ItemsControl
ในไฟล์ generic.xaml ฉันได้สร้างสไตล์สำหรับการควบคุมนั้นและกำหนด ItemTemplate
ด้วย:
<Style TargetType="local:MyItemsControl">
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<Border Background="Red">
<!-- Other things in here -->
</Border>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
ฉันต้องการผูกคุณสมบัติ Background
ของ Border
ใน DataTemplate
กับคุณสมบัติการพึ่งพาของ MyItemsControl
หากพบคำถามหลายข้อที่นี่ แนะนำให้ใช้ชื่อองค์ประกอบของ MyItemsControl
ในการโยง แต่จะใช้ได้เฉพาะเมื่อกำหนด ItemTemplate
ที่ใช้ตัวควบคุมเท่านั้น ฉันยังลองเชื่อมโยงกับ RelativeSource
ซึ่งกำหนด local:MyItemsControl
เป็นประเภทบรรพบุรุษ
ไม่มีอะไรทำงาน ฉันพลาดอะไรไปที่นี่?
ControlTemplate
คุณสามารถใช้ TemplateBinding ได้ แต่จะมีเฉพาะในControlTemplate
s... ฉันจะลองใช้วิธีบรรพบุรุษ - person MVCible   schedule 29.08.2013