最佳做法-列表框中的自定义用户控件绑定

时间:2019-07-04 15:03:57

标签: c# wpf

我有一个正在使用的.Net C#WPF MVVM应用程序,需要将Collection绑定到自定义用户控件(ReviewLetterItem)并在ListBox中列出。我可以使自定义控件正确显示,但不清楚绑定数据的最佳方法。

我最初的方法是构建自定义用户控件的ObservabaleCollection并绑定到ListBox的itemsource。在构建集合时,将为集合中的每个实例填充ReviewLetterItem在ViewModel上的属性。它没有显示任何数据,所以我不确定最佳做法。

            <ListBox 
                Name="ReviewSendListbox" 
                ItemsSource="{Binding ReviewSendList, Mode=TwoWay }" 
                Grid.Column="0" Grid.Row="1" 
                Height="Auto" Width="Auto" MinHeight="400" Margin="0,0,0,0"
                HorizontalAlignment="Left"  VerticalAlignment="Top" 
                SelectionMode="Single">
                <ListBox.ItemTemplate >
                    <DataTemplate>
                        <items:ReviewLetterItem Content="{Binding}"/>
                    </DataTemplate> 
                </ListBox.ItemTemplate>
            </ListBox>

0 个答案:

没有答案
相关问题