【发布时间】:2020-09-28 12:46:35
【问题描述】:
我正在标签页眉中创建一个弹出窗口,我想将列表绑定到弹出窗口内的列表框。但绑定不起作用。此弹窗位于选项卡控件的控件模板内。
<Popup PlacementTarget="{Binding ElementName=ConnectionListDropDownButton}" IsOpen="{Binding ElementName=ConnectionListDropDownButton, Path=IsChecked}" AllowsTransparency="True" PopupAnimation="Slide" StaysOpen="False">
<Grid>
<ListBox Name="ConnectionList" ItemsSource="{Binding tabItems}" Background="White" SelectionChanged="ConnectionList_SelectionChanged" MaxHeight="300" BorderBrush="LightGray" BorderThickness="1" SelectionMode="Single" SelectedIndex="-1">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Header}"></TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Popup>
这是我需要绑定的清单。
public ObservableCollection<TabItem> tabItems { get; set; } =
new ObservableCollection<TabItem>();
【问题讨论】:
-
tabItems是在哪里定义的? -
绑定有什么问题?它表现如何?
-
@mm8 tabitems 定义在包含 tabcontrol 的用户控件中
-
@PeterBoone tabitems 有元素,但列表框不显示任何内容。
标签: c# wpf wpf-controls