ComboBox VirtualizingStackPanel WPF Programmatically



我正在用编程方式创建一个组合框,但我不知道如何使用c#添加虚拟化堆栈面板。

c#

ComboBox newCombo = new ComboBox();
newCombo.IsEditable = true;
newCombo.DisplayMemberPath = "DisplayName";
newCombo.SelectedValuePath = "Value";
newCombo.SelectedValue = "Value";

XAML

<ComboBox Grid.Row="0" Grid.Column="1" x:Name="cbOrigin" Grid.ColumnSpan="2" IsEditable="True"
DisplayMemberPath="DisplayName"
SelectedValuePath="Value"
SelectedValue="{Binding Path=Value}" >
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel />
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>

可能像这样:

ComboBox newCombo = new ComboBox();
newCombo.IsEditable = true;
newCombo.DisplayMemberPath = "DisplayName";
newCombo.SelectedValuePath = "Value";
newCombo.SelectedValue = "Value";
newCombo.ItemsPanel = new ItemsPanelTemplate(new 
FrameworkElementFactory(typeof(VirtualizingStackPanel)));

相关内容

  • 没有找到相关文章

最新更新