![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| | Custom Data Binding with ItemsControl ControlTemplate Problem Hi~~ I encounter a problem. I want to use ItemsControl and Binding my list data to ItemsSource such as <ListBox ItemsSource={Binding myData...etc}/> then define DataTempalte for myData <DataTemplate TargetType={x:Type local.myData}> <Rectangle Fill="Red"/> </DataTempalte> And I define a new Template for ListBox <Style TargetType="{x:Type ListBox}"> .... <ControlTemplate> <local:MyPanel IsItemsHost="true"/> </ControlTempalte> </Style> I want to layout rectangles( represent mydata by DataTemplate) on MyPanel So I override ArrangeOverride Function and write code below foreach( UIElement u in Children) .....etc But I find that I get all "ContentPresenter", not Rectangles. If there's any way to get real controls from MyPanel? Thanks |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Custom Data Binding with ItemsControl ControlTemplate Problem The fact that you are getting ContentPresenter is extremelly normal and corresponds to the actual design of the ItemsControl... Each item in the ItemsControl is represented by an Item Container, now the Item Container Template MUST contain a ContentPresenter, since it is the ContentPresenter that will be the control in charge of displaying your data. To obtain you rectangle object, what you must do is get the first child of the ContentPresenter... The ContentPresenter's child will be the root element of the data template used to display your data. To get the child of the ContentPresenter, you can use VisualTreeHelper.GetChild(u, 0) HolaMan wrote: > Hi~~ I encounter a problem. > > I want to use ItemsControl and Binding my list data to ItemsSource > such as > <ListBox ItemsSource={Binding myData...etc}/> > > then define DataTempalte for myData > <DataTemplate TargetType={x:Type local.myData}> > <Rectangle Fill="Red"/> > </DataTempalte> > > And I define a new Template for ListBox > <Style TargetType="{x:Type ListBox}"> > ... > <ControlTemplate> > <local:MyPanel IsItemsHost="true"/> > </ControlTempalte> > </Style> > > I want to layout rectangles( represent mydata by DataTemplate) on > MyPanel > So I override ArrangeOverride Function and write code below > > foreach( UIElement u in Children) > .....etc > > But I find that I get all "ContentPresenter", not Rectangles. > If there's any way to get real controls from MyPanel? > > Thanks |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Custom Data Binding with ItemsControl ControlTemplate Problem Dear Marcus I got it... Thanks you very much :-) |
My System Specs![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| wpf xml twoway data binding problem? | .NET General | |||