English 中文(简体)
具有约束力的名单
原标题:wpf binding nested list

我试图在一份清单中显示这份nes名单。

例如,如果事件情况有反应,我需要重复每一次事件的名称×时间。 每份答复都有3个检查箱。

我试图做的是名单显示:

• 应急方案——和;

我不想使用树木,因此,清单单行。 任何想法?

最新资料:

我要说的是,我有2项活动和1项活动,有2项选择,活动2为3项选择。 每个方案都有3个检查箱。

我如何试图显示数据:

Event 1         Response A       [X]   [ ]   [ ]
Event 1         Response B       [ ]   [X]   [X]
Event 2         Response A       [X]   [X]   [X]
Event 2         Response D       [ ]   [ ]   [X]
Event 2         Response E       [X]   [X]   [X]

反应 我需要重复活动名称。

public class EventItem: DataAttributeChecked
{
    public EventItem(int primaryKey, string value) : base(primaryKey, value)
    {
        ResponseOptions = new List<ResponseOption>();
    }

    public List<ResponseOption> ResponseOptions { get; set; }
}

public class ResponseOption: DataAttribute
{
    public ResponseOption(int primaryKey, string value, int eventId) : base(primaryKey, value)
    {
        _eventId = eventId;
        LevelOfEfforts = new List<DataAttributeChecked>();
    }

    public List<DataAttributeChecked> LevelOfEfforts { get; set; }

    private readonly int _eventId;

    public int EventId
    {
        get { return _eventId; }
    }
}

<ListBox.ItemTemplate>
    <DataTemplate>
        <Border Margin="3" CornerRadius="2" BorderBrush="CadetBlue" BorderThickness="1">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"></ColumnDefinition>
                    <ColumnDefinition Width="*"></ColumnDefinition>
                    <ColumnDefinition Width="*"></ColumnDefinition>
                    <ColumnDefinition Width="*"></ColumnDefinition>
                </Grid.ColumnDefinitions>


                <StackPanel Grid.Column="0" Orientation="Horizontal">
                    <CheckBox IsChecked="{Binding RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}, Path=IsSelected}" />

                    <TextBlock Text="{Binding Value}" VerticalAlignment="Center"/>
                </StackPanel>

                <StackPanel Grid.Column="1" Orientation="Horizontal">
                    <TextBlock Text="{Binding ResponseOption.Value}" VerticalAlignment="Center"/>   
                </StackPanel>

                <StackPanel Grid.Column="2" Orientation="Horizontal">
                    <ListBox ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
                             ItemsSource="{Binding ResponseOptions.LevelOfEffort}" 
                             Name="lstOption" 
                             SelectionMode="Multiple" >

                        <ListBox.ItemsPanel>
                            <ItemsPanelTemplate>
                                <WrapPanel IsItemsHost="True" />
                            </ItemsPanelTemplate>
                        </ListBox.ItemsPanel>

                        <ListBox.ItemContainerStyle>
                            <Style TargetType="ListBoxItem">
                                <Setter Property="IsSelected" Value="{Binding Path=IsChecked, Mode=TwoWay}"/>
                            </Style>
                        </ListBox.ItemContainerStyle>

                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal" Margin="3,3,3,3">
                                    <CheckBox IsChecked="{Binding RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}, Path=IsSelected}" />
                                    <TextBlock Text="{Binding Value}" VerticalAlignment="Center"/>
                                </StackPanel>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                </StackPanel>

            </Grid>
        </Border>
    </DataTemplate>
                    </ListBox.ItemTemplate>
问题回答

If the list is nested, you have a tree, for which you can use a HierarchicalDataTemplate and display in a TreeView or nested ListViews.

If you want to view in a flat list, have your ViewModel flatten the tree, assuming you are using an MVVM pattern.





相关问题
WPF convert 2d mouse click into 3d space

I have several geometry meshes in my Viewport3D, these have bounds of (w:1800, h:500, d:25). When a user clicks in the middle of the mesh, I want the Point3D of (900, 500, 25)... How can I achieve ...

Editing a xaml icons or images

Is it possible to edit a xaml icons or images in the expression design or using other tools? Is it possible to import a xaml images (that e.g you have exported) in the expression designer for editing?...

WPF: writing smoke tests using ViewModels

I am considering to write smoke tests for our WPF application. The question that I am faced is: should we use UI automation( or some other technology that creates a UI script), or is it good enough to ...

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

How do WPF Markup Extensions raise compile errors?

Certain markup extensions raise compile errors. For example StaticExtension (x:Static) raises a compile error if the referenced class cannot be found. Anyone know the mechanism for this? Is it baked ...

WPF design-time context menu

I am trying to create a custom wpf control, I m wondering how I can add some design-time features. I ve googled and can t seem to get to my goal. So here s my simple question, how can I add an entry ...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签