WPF - Binding a list of a string to a column in Data Grid

前端 未结 1 1574
名媛妹妹
名媛妹妹 2020-12-22 13:00

I have a datagrid with three columns.

 
       
           

        
相关标签:
1条回答
  • 2020-12-22 13:34

    Your problem seems to be that you add the StackPanel as item to the ItemsControl instead of using it in a DataTemplate.

    Instead of

    <ItemsControl ItemSource="{Binding SomeList}">
        <StackPanel Orientation="Horizontal">
            <TextBlock Text="SomeTopic"/>
            <ComboBox ItemSource="{Binding }"/>
        </StackPanel>
    </ItemsControl>
    

    it should look like this:

    <ItemsControl ItemSource="{Binding SomeList}">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="SomeTopic"/>
                    <ComboBox ItemSource="{Binding }"/>
                </StackPanel>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
    
    0 讨论(0)
提交回复
热议问题