2011-05-04 46 views
0

自定義控件XAML元素

控制:

ControlX:IControlX和ControlY:IControlY

ControlZ具有ControlX的列表屬性

接口:

IControlX和IControlY :IControlX

Th Ë標籤,我得到的是:

<ControlZ> 

     <ControlY> 

      <ControlX></ControlX> 

      <ControlX></ControlX> 

     </ControlY> 

</ControlZ> 

在這裏,我可以訪問ControlY在列表中,但無法訪問控制X.

但如果我改變標籤序列爲:

<ControlZ> 

     <ControlY> </ControlY> 

     <ControlX></ControlX> 

     <ControlX></ControlX>  

</ControlZ> 

我可以獲取列表中的所有對象。

但這是不合邏輯的,所以我需要維護標籤後續。

您能否給我建議。我如何訪問內部標籤?

謝謝

回答

0

你不能那樣做。 XAML不允許您訪問屬性的屬性,除非您在XAML中初始化它們。

<Control:MyControl> 

    <Control:MyControl.Property1> 

     <!-- Assuming that Property1 is of type MyOtherControl --> 
     <Control:MyOtherControl Property="somevalue" /> 

</Control:MyControl.Property1> 

</Control:MyControl> 
0

爲了設置的Property1屬性的值,你必須先實例化它。假設存在於相同名稱空間中的Property1Type類型的Property1 os和內部屬性(Property)的類型是InnerPropertyType,它也位於同一名稱空間中。你的代碼應該是這樣的:

<Control:MyControl> 
    <Control:MyControl.Property1> 
     <Control:Property1Type> 
      <Control:Property1Type.Property> 
       <Control:InnerPropertyType /> 
      </Control:Property1Type.Property> 
     </Control:Property1Type> 
    </Control:MyControl.Property1> 
</Control:MyControl> 

這是類似的,例如:

<ListBox> 
    <ListBox.BorderBrush> 
    <ImageBrush> 
     <ImageBrush.Transform> 
      <ScaleTransform ScaleX="5"/> 
     </ImageBrush.Transform> 
    </ImageBrush> 
    </ListBox.BorderBrush> 
</ListBox> 

這應該解決的一些問題,如果其他仍然存在,請更新您的問題;)

希望這有助於:)