ComboBox VirtualizingStackPanel WPF 以编程方式
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)));
我正在以编程方式创建组合框,但我不知道如何使用 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)));