wpf中xaml设计了一个DataTemplate ,TabControl的TabItem应用这个DataTemplate ,后台拿得到数据,界面上却不显示数据,代码如下,希望大虾们指点迷津。不用DataTemplate,每个 TabItem都写一大串相同的DataTemplate 这样的xaml能显示数据,好奇怪
<meta:ClosableUserControl.Resources>
<DataTemplate x:Key="DataTemplate1">
<Grid>
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<DataGrid x:Name="procDataGrid1" SelectedItem="{Binding SelectedDishMenuItem, Mode=TwoWay}" Grid.Row="0" ItemsSource="{Binding DishMemu, Mode=TwoWay}" IsReadOnly="True" AutoGenerateColumns="False" GridLinesVisibility="All">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<ei:CallMethodAction TargetObject="{Binding DataContext, ElementName=mainWindow}" MethodName="DataGrid_SelectionChanged"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<DataGrid.Columns>
<DataGridTextColumn Header="菜名" Binding="{Binding Name}" Width="120"/>
<DataGridTextColumn Header="种类" Binding="{Binding Category}" Width="120"/>
<DataGridTextColumn Header="点评" Binding="{Binding Comment}" Width="120"/>
<DataGridTextColumn Header="推荐指数" Binding="{Binding Score}" Width="120"/>
</DataGrid.Columns>
</DataGrid>
<StackPanel Grid.Row="1" DataContext="{Binding UpdateDishMenuItem, Mode=TwoWay}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="菜名:" />
<TextBox Text="{Binding Name, Mode=TwoWay}"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="种类:" />
<TextBox Text="{Binding Category, Mode=TwoWay}"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="点评:" />
<TextBox Text="{Binding Comment, Mode=TwoWay}"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="推荐指数:" />
<TextBox Text="{Binding Score, Mode=TwoWay}"/>
</StackPanel>
</StackPanel>
</Grid>
</Grid>
</DataTemplate>
</meta:ClosableUserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Row="0" Grid.ColumnSpan="2" Orientation="Horizontal">
<StackPanel Orientation="Horizontal" Margin="5" >
<TextBlock Text="生产号:"/>
<TextBox Width="150" Text="{Binding QueryCondition.TankNo, Mode=TwoWay}"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="5">
<TextBlock Text="工作日:"/>
<DatePicker SelectedDateFormat="Short" />
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="5">
<TextBlock Text="班次:"/>
<ComboBox>
<ComboBoxItem Content="甲班" />
<ComboBoxItem Content="乙班" />
</ComboBox>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="5">
<TextBlock Text="工作令:"/>
<TextBox Width="150" Text="{Binding QueryCondition.WorkOrder}"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="5">
<Button Content="查询">
</Button>
</StackPanel>
</StackPanel>
<TabControl Name="tab" Grid.Row="1" Grid.RowSpan="2">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<ei:CallMethodAction TargetObject="{Binding DataContext, ElementName=mainWindow}" MethodName="Tab_Loaded"/>
</i:EventTrigger>
<i:EventTrigger EventName="SelectionChanged">
<ei:CallMethodAction TargetObject="{Binding DataContext,ElementName=mainWindow}" MethodName="Tab_SelectionChanged"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<TabItem x:Name="tab1" Header="筒体班" ContentTemplate="{StaticResource DataTemplate1}"/>
<TabItem x:Name="tab2" Header="罐体班" ContentTemplate="{StaticResource DataTemplate1}"/>
帮顶...........
谢谢
<TabControl Name="tab" Grid.Row="1" Grid.RowSpan="2" ItemsSource="{Binding ShiftList}">
<TabControl.ItemTemplate>
<DataTemplate>
<!--Header -->
<TextBlock Text="{Binding EntityName}" Tag="{Binding Entityid}" />
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate>
<Grid>
……
</Grid>
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
TabControl.ItemTemplate是Header 的模板,TabControl.ContentTemplate是TabItem的模板,绑定各种集合自动显示出相应的不同Header 的TabItem