有点难以解释...
我有一个主窗口,其中包含带有7个选项卡的TabControl:价格表选项卡包含Listview和TextBoxes。该列表显示数据库中的价格表。当我选择(单击)任何价格列表时,“选定”项目将突出显示,并且“文本框”将填充选定数据。
问题:仅当ListView位于主Windows中时,此方法才有效。如果我将所有内容放到Tab中并运行它,则后面的代码可以正常工作,但ListView不会突出显示所选的List项,或者它不会填充TextBoxes。基本上,绑定不显示更改。
<UserControl ....>
<ListView x:Name="ListViewPriceLists" ItemsSource="{Binding ListOfPriceLists}" SelectedItem="{Binding SelectedPriceList, Mode=TwoWay}" >
<ListView.View>
<GridView>
<GridViewColumn Width="300" DisplayMemberBinding="{Binding Reference}" >
<GridViewColumn.Header>
<GridViewColumnHeader Tag="Description" Click="GridViewColumnHeader_Click">Description</GridViewColumnHeader>
</GridViewColumn.Header>
</GridViewColumn>
<GridViewColumn Width="300" DisplayMemberBinding="{Binding Description}" >
<GridViewColumn.Header>
<GridViewColumnHeader Tag="Description" Click="GridViewColumnHeader_Click">Description</GridViewColumnHeader>
</GridViewColumn.Header>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
MainWindow.xaml
<!-- PRICE LIST -->
<TabItem x:Name="TabItemPriceList" Header="PRICE LIST" GotFocus="TabItemPriceList_GotFocus" IsSelected="True" >
<DockPanel LastChildFill="True">
<Grid x:Name="GcPriceList" >
</Grid>
</DockPanel>
</TabItem>
MainWindow.xaml.cs
private void TabItemPriceList_GotFocus(object sender, RoutedEventArgs e)
{
GcPriceList.Children.Clear();
PiceListUC piceListUC = new PiceListUC();
GcPriceList.Children.Add(piceListUC);
}