里面ListBoxItem中复杂的UI [英] Complex UI inside ListBoxItem

查看:214
本文介绍了里面ListBoxItem中复杂的UI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在WPF中,我可以通过提供列表框与<$ C $添加任何UI进入 ListBoxItem的取值C> ItemTemplate中:

 &LT;列表框的ItemsSource ={结合}&GT;
            &LT; ListBox.ItemTemplate&GT;
                &LT;的DataTemplate&GT;
                    &所述;边框了borderThickness =1BorderBrush =灰色CornerRadius =8填充=4,0,4,0&GT;
                        &LT;电网&GT;
                            &LT; Grid.ColumnDefinitions&GT;
                                &LT; ColumnDefinition WIDTH =50/&GT;
                                &LT; ColumnDefinition /&GT;
                            &LT; /Grid.ColumnDefinitions>

                            &LT; Grid.RowDefinitions&GT;
                                &LT; RowDefinition /&GT;
                                &LT; RowDefinition /&GT;
                                &LT; RowDefinition /&GT;
                            &LT; /Grid.RowDefinitions>

                            &LT;复选框Grid.Column =1CONTENT =有效客户=器isChecked{结合IsActive}/&GT;

                            &LT;标签内容=ID:Grid.Row =1的Horizo​​ntalAlignment =右/&GT;
                            &LT;标签内容=名称:Grid.Row =2的Horizo​​ntalAlignment =右/&GT;

                            &所述;文本框的文本={结合标识}Grid.Row =1Grid.Column =1/&GT;
                            &LT;文本框文本={结合名}Grid.Row =2Grid.Column =1/&GT;
                        &LT; /网格&GT;
                    &LT; /边框&GT;
                &LT; / DataTemplate中&GT;
            &LT; /ListBox.ItemTemplate>
        &LT; /列表框&GT;
 

结果是:

有没有办法在Windows窗体来实现相同的?

编辑:

1 - 有什么办法来实现Windows窗体一样,同时保持分离视图之间的关注 应用逻辑以这样的方式,如果我以后想完全重新定义查看,我不会'不用为了重构整个应用程序?

2 - 是否WinForms的支持数据绑定在这样一种方式,我的每一个 ListBoxItems 可以绑定到一个复杂的实体,最终包括模型数据的中间类型转换UI数据和背部,因为我没有写吨的样板code填充视图,然后通过UI值回复到模型的方式为了节省?

3 - 如果我想介绍动画以这样一种方式,目前的SelectedItem 将起劲拓展自己成某种行详细信息模式,在这里你可以看到很多的附加信息?

4 - 是否WinForms的支持 UI虚拟化以这样的方式,如果我有,比如说1万件商品它并不需要一生的时间去加载UI,并且只呈现什么明显的在屏幕上?

5 - 说我想介绍复杂图形的方程。是的WinForms渲染硬件加速?

6 - 如何使这一切分辨率独立以这样一种方式,列表框及其所有内容延伸到可用的窗口大小,以充分利用更大的屏幕,而保持兼容性与更小的?

7 - 它被建议使用的ListView 控件,而不是普通的列表框,请问的ListView 提供任何UI添加到它的能力吗?我可以添加视频,例如每个项目?或保存和编辑按钮复杂的主/从模板?

8 - 的WinForms是否提供一致和充分文档模型,能够创造高-fidelity所见即所得的文件和其他类型的丰富内容?

解决方案

要回答的首要问题 - 怎样才能做到这一点的WinForms - 我建议如下:

  1. 使用一个WPF列表框在你的WinForms应用程序,包裹在一个ElementHost的。这有其自身的问题,但我认为这是获得预期的效果最彻底的方法。

    如果不符合这个要求,那么

  2. 使用第三方控制套件,具有支持该(Infragistics的和DevEx preSS都这样做)的组件。

  3. 旋转自己的派生ListBox控件,它覆盖漆等来渲染所需的内容。

要你的个人问题:

  1. 有没有什么办法来实现Windows窗体一样,同时保持分离的​​ >查看应用逻辑以这样的方式,如果我以后想完全重新定义查看,我就不会去重构整个应用程序?
    在过去,我已经使用了MVP(模型 - 视图 - presenter)模式与Windows窗体。它适用于从业务逻辑分离视图,虽然没有干净与WPF的MVVM方法。我能给出的最好的建议是:不要把业务逻辑的事件处理程序。

  2. 是否WinForms的支持数据绑定在这样一种方式,我的每一个 ListBoxItems 可以绑定到一个复杂的实体,最终包括模型数据的中间类型转换UI数据和背部,以这样的方式,我没有写吨的样板code填充视图,然后通过在UI值回为了示范救?
    第Windows窗体数据绑定不支持复杂数据绑定。您可以实现通过ICustomTypeDescriptor或IBindingSource自己的东西,可以采取复杂的路径,并评估它们结合的目的......但没有任何存在的开箱即用的这个。

  3. 如果我想介绍动画以这样一种方式,目前的SelectedItem 将生动地扩大自己变成某种行详细信息模式,在这里你可以看到很多的附加信息?
    你必须推出自己的Windows窗体列表框和ListBoxItems并覆盖绘制操作。

  4. 的WinForms是否支持 UI虚拟化以这样的方式,如果我有,比如说1万件商品它并不需要一辈子加载UI,并且只会使什么是可见的屏幕上?
    不开箱,但一些第三方控制套件具有支持类型的虚拟化组件...但一​​点都没有以同样的方式WPF一样。

  5. 说我想介绍复杂图形的方程。是的WinForms渲染硬件加速?
    Windows窗体是基于GDI +。 GDI +是不是硬件加速: Windows窗体的Windows7下很慢

  6. 如何让这一切分辨率独立以这样一种方式,列表框及其所有内容延伸到可用的窗口大小为了同时保持较小的兼容性,以充分利用更大的屏幕?
    您可以使用停靠和锚定在Windows窗体来实现这一目标。或者,您可以添加自定义事件处理程序来执行基于分辨率​​和窗口大小适当的布局调整。

  7. 它被建议使用的ListView 的控制,而不是一个普通的列表框,请问的ListView 提供任何UI添加到它的能力吗?我可以添加视频,例如每个项目?或保存和编辑按钮复杂的主/从模板?
    这简化了......但一​​个ListView很简单,就是支持多种视图类型的列表框。它也更有限的数据绑定的条款。 <一href="http://blog.gfader.com/2008/09/winforms-listbox-vs-listview.html">http://blog.gfader.com/2008/09/winforms-listbox-vs-listview.html.

  8. 有没有的WinForms提供一致和充分的[文档模型] [2],使创建高保真所见即所得的文件和其他类型的丰富内容?
    一点都不。没有哪怕是一点点。

总之,如果它是一个可接受的解决方案,我想换你的WPF的ListView在ElementHost的和收工。

In WPF, I can add whatever UI into ListBoxItems by providing the ListBox with an ItemTemplate:

 <ListBox ItemsSource="{Binding}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Border BorderThickness="1" BorderBrush="Gray" CornerRadius="8" Padding="4,0,4,0">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="50"/>
                                <ColumnDefinition/>
                            </Grid.ColumnDefinitions>

                            <Grid.RowDefinitions>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>

                            <CheckBox Grid.Column="1" Content="Is Active Customer" IsChecked="{Binding IsActive}"/>

                            <Label Content="Id:" Grid.Row="1" HorizontalAlignment="Right"/>
                            <Label Content="Name:" Grid.Row="2" HorizontalAlignment="Right"/>

                            <TextBox Text="{Binding Id}" Grid.Row="1" Grid.Column="1"/>
                            <TextBox Text="{Binding Name}" Grid.Row="2" Grid.Column="1"/>
                        </Grid>
                    </Border>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

Results in:

Is there any way to achieve the same in Windows Forms?

Edit:

1 - Is there any way to achieve the same in Windows Forms, all while maintaining separation of concerns between the View and the Application Logic in such a way that if I later wanted to completely redefine the View, I wouldn't have to refactor the entire application?

2 - Does winforms support databinding in such a way that each of my ListBoxItems can be bound to a complex Entity, eventually including an intermediate type conversion from Model data to UI data and back, in such a way that I don't have to write tons of boilerplate code to populate the view and then pass the UI values back into the Model in order to save?

3 - What if I wanted to introduce Animations in such a way that the currently SelectedItem would animatedly expand itself into some kind of "Row Details" mode, where you can see a lot of additional information?

4 - Does winforms support UI Virtualization in such a way that if I have, say 1 million items it doesn't take a lifetime to load the UI, and only render what's visible on screen?

5 - Say I wanted to introduce complex graphics to the equation. Is winforms rendering hardware-accelerated?

6 - How do I make all this Resolution Independent in such a way that the ListBox and all its contents stretch to the available window size in order to leverage larger screens while maintaining compatibility with smaller ones?

7 - It's been suggested to use the ListView control instead of a regular ListBox, does the ListView provide the ability to add ANY UI into it? can I add Videos for example for each item? or a complex Master/Detail template with Save and edit Buttons?

8 - Does winforms provide a consistent and adequate Document Model that enables the creation of high-fidelity WYSIWYG documents and other types of rich content?

解决方案

To answer the overarching question - how to do this in WinForms - I'd suggest the following:

  1. Use a WPF ListBox in your WinForms application, wrapped in an ElementHost. This has its own issues, but I think it's the cleanest way to get the desired effect.

    if that doesn't fit the bill, then

  2. Use a third party control suite that has components which support this (Infragistics and DevExpress both do).

  3. Spin your own derived ListBox control that overrides paint, etc to render the desired content.

To your individual questions:

  1. Is there any way to achieve the same in Windows Forms, all while maintaining separation of concerns between the View and the Application Logic in such a way that if I later wanted to completely redefine the View, I wouldn't have to refactor the entire application?
    In the past, I've used the MVP (model-view-presenter) paradigm with Windows Forms. It works for separating the view from the business logic, albeit not as cleanly as an MVVM approach with WPF. The best advice I can give is: don't put business logic in event handlers.

  2. Does winforms support databinding in such a way that each of my ListBoxItems can be bound to a complex Entity, eventually including an intermediate type conversion from Model data to UI data and back, in such a way that I don't have to write tons of boilerplate code to populate the view and then pass the UI values back into the Model in order to save?
    No. Windows Forms databinding does not support complex data binding. You could implement something yourself via ICustomTypeDescriptor or IBindingSource that can take complex paths and evaluate them for binding purposes...but nothing exists out of the box for this.

  3. What if I wanted to introduce Animations in such a way that the currently SelectedItem would animatedly expand itself into some kind of "Row Details" mode, where you can see a lot of additional information?
    You'd have to roll your own Windows Forms ListBox and ListBoxItems and override the paint operations.

  4. Does winforms support UI Virtualization in such a way that if I have, say 1 million items it doesn't take a lifetime to load the UI, and only render what's visible on screen?
    Not out of the box, but some third party control suites have components that support types of virtualization...but not at all in the same way WPF does.

  5. Say I wanted to introduce complex graphics to the equation. Is winforms rendering hardware-accelerated?
    Windows Forms is based on GDI+. GDI+ is not hardware accelerated: Windows Forms very slow under Windows7?

  6. How do I make all this Resolution Independent in such a way that the ListBox and all its contents stretch to the available window size in order to leverage larger screens while maintaining compatibility with smaller ones?
    You can use Docking and Anchoring in Windows Forms to accomplish this. Or you can add custom event handlers to perform appropriate layout adjustments based on resolution and Window size.

  7. It's been suggested to use the ListView control instead of a regular ListBox, does the ListView provide the ability to add ANY UI into it? can I add Videos for example for each item? or a complex Master/Detail template with Save and edit Buttons?
    This is simplifying...but a ListView is simply a ListBox that supports multiple view types. It is also more limited in terms of databinding. http://blog.gfader.com/2008/09/winforms-listbox-vs-listview.html.

  8. Does winforms provide a consistent and adequate [Document Model][2] that enables the creation of high-fidelity WYSIWYG documents and other types of rich content?
    No. Not at all. Not even a little bit.

In short, if it's an acceptable solution, I'd wrap your WPF ListView in an ElementHost and call it a day.

这篇关于里面ListBoxItem中复杂的UI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆