开发者

How should the WPF code look to achieve nested reusability

开发者 https://www.devze.com 2023-03-31 07:53 出处:网络
This is a simple case, that I am having difficulty understanding nesting types in xaml. Say you have a myusercontrol.xaml

This is a simple case, that I am having difficulty understanding nesting types in xaml. Say you have a myusercontrol.xaml

and you want to declarativly pass data to it like this:

  <my:MyUserControl x:Name="myUserControl1" >
        <my:PointCollection>
            <my:point>33,12</my:point>
            <my:point>11,12</my:point>
        </my:PointCollection>
        <my:PointCollection>
            <my:point>33,12</my:point>
            <my:point>11,12</my:point>
        </my:PointCollection>
    </my:MyUserControl>

What would MyUserControl.xaml/.cs have to look like to accept this Enumeration of Point collection dependency.

Second question would be, how do i reform开发者_C百科ulate the xaml usage above so that i can databind to a Enumerable to myUserControl1.DataContext.


For databinding to an enumerable, use a Collection View. See the Remarks and Examples sections.

<MyUserControl.DataContext>
  <Binding Source="{StaticResource pointCollection}"/>
</MyUserControl.DataContext>
0

精彩评论

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