Tabcontrol绑定的Observable Collection

时间:2016-08-30 14:19:43

标签: c# wpf xaml

    <TabControl HorizontalAlignment="Stretch" TabStripPlacement="Left" Margin="10,20,0,0"  Name="tabControl2" ItemsSource="{Binding NotesObs}" VerticalAlignment="Stretch" MinHeight="80">
        <TabItem Header="Contract Read and understood, proposal letter read and understood." Name="tabItem2" FontSize="14" IsEnabled="True">
            <Grid>
                <Border Name="b_desc"/>
                <TextBox HorizontalAlignment="Stretch" Margin="0"  Name="textBox5" Text="{Binding ContractText}"

                                         VerticalAlignment="Stretch" FontSize="12" TextWrapping="Wrap" 
                                         AutoWordSelection="True" VerticalScrollBarVisibility="Auto" 
                                         AcceptsReturn="True" 
                                         Width="{Binding ElementName=b_desc, Path=ActualWidth}" 
                                         Height="{Binding ElementName=b_desc, Path=ActualHeight}" 
                                         MaxWidth="{Binding ElementName=b_desc, Path=Width}" 
                                         MaxHeight="{Binding ElementName=b_desc, Path=Height}" />
            </Grid>
        </TabItem>
    </TabControl>

上面是我的Xaml,我的ObsCollection的名字是

public ObservableCollection<NotesDisplay> NotesObs { get; set; }

我已在NotesDisplay模型中正确声明了ContractText列。由于某种原因,我无法将其绑定,但这在数据网格中有效。有人可以解释我在XAML中做错了吗?

由于

编辑:我查看了链接的解决方案,但是当我运行程序时,标签没有显示出来。它们在xaml

中显示
<UserControl x:Class="CAT_Application_WPF.UI.NotesPage"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:CAT_Application_WPF.UI"
             xmlns:viewModel="clr-namespace:CAT_Application_WPF.ViewModel"
             xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
             mc:Ignorable="d" 
             xmlns:oxy="http://oxyplot.org/wpf"
             d:DesignHeight="640">

    <Grid Margin="0,0,0,0" Background="{DynamicResource {x:Static SystemColors.GradientActiveCaptionBrushKey}}" d:DataContext="{d:DesignInstance viewModel:NotesPageViewModel}" >

        <Grid.RowDefinitions>
            <RowDefinition Height="60*"></RowDefinition>

        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="300"></ColumnDefinition>
            <ColumnDefinition Width="400"></ColumnDefinition>

        </Grid.ColumnDefinitions>

        <TabControl HorizontalAlignment="Stretch" ItemsSource="{Binding NotesObs}" TabStripPlacement="Top"   x:Name="_tabControl"  VerticalAlignment="Stretch" MinHeight="80" Grid.ColumnSpan="2" Margin="121,28,279,-28">
            <TabControl.ItemTemplate>
                <DataTemplate>
                    <TextBlock>                            
                <TextBlock Text="{Binding ContractText}"/> 
            </TextBlock>
                </DataTemplate>
            </TabControl.ItemTemplate>
            <TabControl.ContentTemplate>
                <DataTemplate>
                    <TextBlock>                            
                This is <TextBlock Text="{Binding EMSText}"/>
            </TextBlock>
                </DataTemplate>
            </TabControl.ContentTemplate>
        </TabControl>
    </Grid>
</UserControl>

1 个答案:

答案 0 :(得分:0)

现在它还可以,但你必须在另一个TextBlock内删除你的TextBlock。

您可以更改

<TextBlock>                            
  <TextBlock Text="{Binding ContractText}"/> 
</TextBlock>

<TextBlock Text="{Binding ContractText}"/> 

并且

<TextBlock>                            
  This is <TextBlock Text="{Binding EMSText}"/>
</TextBlock>

类似于

<StackPanel Orientation="Horizontal">
  <TextBlock>This is</TextBlock>
  <TextBlock Text="{Binding EMSText}"/>
</StackPanel>