Syncfusion TaskBar绑定

时间:2017-09-14 22:40:54

标签: wpf mvvm syncfusion

我试图将Syncfusion TaskBar绑定到ObservableCollection,并有一个TaskBarItem列表。 使用代码隐藏,项目添加如下:

TaskBar taskBar = new TaskBar();
TaskBarItem taskBarItem1 = new TaskBarItem();
taskBarItem1.Header = "TaskBarItem1";
TextBlock textBlock1 = new TextBlock();
textBlock1.Text = "This TaskBar that have a TaskBarItem.";
taskBarItem1.Items.Add(textBlock1);          
taskBar.Items.Add(taskBarItem1);

这个XAML:

<syncfusion:TaskBar Grid.Row="1"
                VerticalAlignment="Stretch"
                ItemsSource="{Binding Path=DataContext.Categories, RelativeSource={RelativeSource AncestorType=localV:MainWindow}}">
    <syncfusion:TaskBar.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Path=FirstName}"/>
        </DataTemplate>
    </syncfusion:TaskBar.ItemTemplate>
</syncfusion:TaskBar>

给我一​​个TaskBarItems列表,其中Header显示FirstName,而任何TaskBarItem的可扩展区域都没有。如何在可扩展区域中使用正确的绑定/模板来查看标题和数据?

1 个答案:

答案 0 :(得分:1)

我希望您能够定义ItemContainerStyleContentTemplate

<syncfusion:TaskBar Grid.Row="1"
                VerticalAlignment="Stretch"
                ItemsSource="{Binding Path=DataContext.Categories, RelativeSource={RelativeSource AncestorType=localV:MainWindow}}">
    <syncfusion:TaskBar.ItemContainerStyle>
        <Style TargetType="syncfusion:TaskBarItem">
            <Setter Property="Header" Value="{Binding Path=FirstName}" />
            <Setter Property="Content">
                <Setter.Value>
                    <TextBlock>This TaskBar that have a TaskBarItem</TextBlock>
                </Setter.Value>
            </Setter>
        </Style>
    </syncfusion:TaskBar.ItemContainerStyle>
</syncfusion:TaskBar>