简体   繁体   中英

Displaying a list of Items in a WPF form using XAML

I am attempting to display a list of items (the style and controltemplate for these items are defined elsewhere) and i want to be able to add/remove as many as i want to. As i do not have infinite screen realestate I am displaying these in a ListBox control.

This is the screen i have to date:

替代文字

What is going to happen is this. When i click the New button, i want the item to appear in the outlined area.

So now for the problem:

I want, when i click the New... Button, a new item to appear in the ListBox (outlined). Is it possible to do this using XAML? I am trying to work on seperating the business logic from the interface, so if there were some way to acheive this in XAML i would appreciate it. If not,can i use the custom templated item i have created in C# so that it will appear as the template specifies in the list box instead of like a normal ListBoxItem

Thanks in advance!

I think the only way to achieve this is to add the new (empty) item to the list to which the outlined listview is databound.

If there's any business logic involved in creating the new item you should ask your business logic layer to create the new item for you, otherwise instantiate the object as you would normally do.

you can use ObesrvableCollection for this purpose. Use twoway binding to show the details should be displayed in the list while typing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM