开发者

Custom Control Xaml Elements

I have

controls :

ControlX :IControlX and ControlY:IControlY

Contr开发者_开发问答olZ has a List Property of ControlX

Interfaces :

IControlX and IControlY:IControlX

The Tags I am getting is:

<ControlZ>

        <ControlY>

            <ControlX></ControlX>

             <ControlX></ControlX>

        </ControlY>

</ControlZ>

Here I can access the ControlY in the List but Not able access Control X.

But If I change the tag sequence as :

<ControlZ>

        <ControlY> </ControlY>

        <ControlX></ControlX>

         <ControlX></ControlX>       

</ControlZ>

I can Get the all the object in the list.

But it is not logical so I need to maintain the tag sequece.

Can you please suggest me . How can I get access of the inner tags ?

Thank You


You can't do that. XAML does not allow you to access properties of properties unless you initialize them in XAML.

<Control:MyControl>

  <Control:MyControl.Property1>

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

 </Control:MyControl.Property1>

</Control:MyControl>


In order to set a value of a property of Property1, you have to instanciate it first. Let's say that Property1 os of type Property1Type which exists in the same namespace, and the type of the inner property (Property) is InnerPropertyType which is also in the same namespace. You code should be something like:

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

this is similar to, for example:

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

This should solve some of the issues, if other persist, please update your question ;)

Hope this helps :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜