首页 新闻 搜索 专区 学院

wpf应用DataTemplate 不显示数据

0
悬赏园豆:30 [已关闭问题] 关闭于 2014-03-28 10:55

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}"/>

Sunny秋刀鱼的主页 Sunny秋刀鱼 | 初学一级 | 园豆:31
提问于:2014-03-24 11:48
< >
分享
所有回答(2)
0

帮顶...........

【秦时明月】 | 园豆:803 (小虾三级) | 2014-03-24 12:59

谢谢

支持(0) 反对(0) Sunny秋刀鱼 | 园豆:31 (初学一级) | 2014-03-24 13:01
0

<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

Sunny秋刀鱼 | 园豆:31 (初学一级) | 2014-03-28 10:53
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册