Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf NET4.0列表框和ItemsControl_Wpf_.net 4.0 - Fatal编程技术网

Wpf NET4.0列表框和ItemsControl

Wpf NET4.0列表框和ItemsControl,wpf,.net-4.0,Wpf,.net 4.0,我试图用项目填充列表框。ItemsSource如下所示: public SortedDictionary<string, List<int>> AvailableValues 公共分类词典可用值 当我有以下项目似乎是很好的布局。除了我不能选择整个项目并对其执行某些功能 <ScrollViewer Grid.Row="0" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disab

我试图用项目填充列表框。
ItemsSource
如下所示:

public SortedDictionary<string, List<int>> AvailableValues
公共分类词典可用值
当我有以下项目似乎是很好的布局。除了我不能选择整个项目并对其执行某些功能

<ScrollViewer Grid.Row="0" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" >
        <ItemsControl ItemsSource="{Binding AvailableValues}">

            <ItemsControl.Template>
                <ControlTemplate>
                    <CustomControls:UniformWrapPanel IsItemsHost="True"/>
                </ControlTemplate>
            </ItemsControl.Template>

            <ItemsControl.ItemTemplate>
                <DataTemplate>

                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="60"/>
                        </Grid.ColumnDefinitions>


                        <Label  Grid.Row="0" Grid.Column="0" Content="{Binding Key}" />
                        <ComboBox Grid.Row="0" Grid.Column="1" ItemsSource="{Binding Value}" SelectedItem="{Binding SelectedInputValue, UpdateSourceTrigger=PropertyChanged}" IsSynchronizedWithCurrentItem="True" />

                    </Grid>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </ScrollViewer>

我尝试用
列表框
(以及
列表框.ItemTemplate
)替换
项目控件
,但似乎无法显示标签内容左对齐而组合框内容右对齐的内容

UniformWrapPanel
来自CodeProject文章


谢谢,

一个
项目控件
与一个
列表框
不同-它不包含选择功能

最好使用一个实际的列表框并修改ItemTemplate以显示您想要的内容

<ListBox x:Name="MyListBox" ItemsSource="{Binding AvailableValues}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <Grid HorizontalAlignment="Stretch">
                <Grid.RowDefinitions>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="60"/>
                </Grid.ColumnDefinitions>

                <Label  Grid.Row="0" Grid.Column="0" Content="{Binding Key}" />
                <ComboBox Grid.Row="0" Grid.Column="1" ItemsSource="{Binding Value}" />

            </Grid>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

如果对齐是主要问题,您可能希望尝试将标签和组合框包装到网格中。将栅格的水平对齐设置为“拉伸”,并将对象的水平对齐设置为“向左”

设置最小-最大大小是可选的,但可能很有用

<Grid HorizontalAlignment="Stretch">
            <Grid.ColumnDefinitions>
            <ColumnDefinition  MinWidth="55" />
            <ColumnDefinition Width="0.636*" />
            </Grid.ColumnDefinitions>
            <Label Grid.Column="0" HorizontalALignment="Left"/>
            <ComboBox Grid.Column="1" HorizontalAlignment="Left"/>
        </Grid>


谢谢@randyc。奇怪的是,即使使用上面的定义,但在
堆栈面板
中包含的两项设置为
水平
方向
时,它也会丢失绘图。然而,上面的定义起了作用!为瑞秋干杯。即使在
ItemsPanel
下进行
Canvas
设置,我也花了不少时间。最后@randyc的建议成功了。