问题描述
我正在尝试数据绑定两个itemssources。我想我必须重新排列我的xaml。但我不知道该怎么做。
I'm trying to data bind two itemssources. I assume I have to rearrange my xaml. But I don't know how to do this.
如何解决这个问题?
我的xaml:
Page x:Class="Dienstverplaatsing.Page1"
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:Dienstverplaatsing"
mc:Ignorable="d"
d:DesignHeight="450"
Title="Page1" >
<Grid Margin="0,0,0,10">
<DockPanel>
<Menu DockPanel.Dock="Top">
<MenuItem Header="_Bestand">
<MenuItem Header="_Werknemerslijst" />
<MenuItem Header="_Werknemer toevoegen" />
<MenuItem Header="_Afsluiten" />
</MenuItem>
<MenuItem Header="_Persoonlijke gegevens" Click="MenuItem_Click">
</MenuItem>
<MenuItem Header="_Verplaatsingen goedkeuren">
</MenuItem>
<MenuItem Header="_CSV Genereren">
</MenuItem>
</Menu>
</DockPanel>
<TabControl Name="tcYear" Margin="10,20,10,10" TabStripPlacement="left">
<TabItem Header="{Binding Year}">
<TabControl Name="tcMonth" Margin="10,20,10,10" TabStripPlacement="Bottom">
<TabItem Header="{Binding Month}">
<DataGrid Name="dgVerplaatsingen" AutoGenerateColumns="False" ColumnWidth="*" CanUserReorderColumns="False" CanUserAddRows="False" >
<DataGrid.ColumnHeaderStyle>
<Style TargetType="DataGridColumnHeader">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock TextWrapping="Wrap" Text="{Binding}"></TextBlock>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</DataGrid.ColumnHeaderStyle>
<DataGrid.Columns >
<DataGridTextColumn Header="Datum" Binding="{Binding Datum,StringFormat=d}" IsReadOnly="True" Width="75" />
<DataGridTextColumn Header="Omschrijving" Binding="{Binding Omschrijving}" Width="150">
<DataGridTextColumn.ElementStyle>
<Style>
<Setter Property="TextBlock.TextWrapping" Value="Wrap" />
<Setter Property="TextBlock.TextAlignment" Value="Left"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="Km auto" Binding="{Binding Datum}" Width="75" />
<DataGridTextColumn Header="Km fiets" Binding="{Binding Datum}" Width="75" />
<DataGridTextColumn Header="Bedrag parkeren" Binding="{Binding Datum}" Width="75" />
<DataGridTextColumn Header="Bedrag openbaar vervoer" Binding="{Binding Datum}" Width="75" />
<DataGridTextColumn Header="Totaal bedrag" Binding="{Binding Datum}" Width="75" IsReadOnly="True" />
<DataGridTextColumn Header="Aantal Auto" Binding="{Binding Datum}" Width="75" />
<DataGridTextColumn Header="Aantal fiets" Binding="{Binding Datum}" Width="75" />
</DataGrid.Columns>
</DataGrid>
</TabItem>
</TabControl>
</TabItem>
</TabControl>
</Grid>
</Page>
My C sharp:
My C sharp:
List<Kalendar> calendar = new List<Kalendar>
{
new Kalendar() { Year={ 2017,2018,2019 }, Month={ "Jan", "febr", "mrt", "april", "juli", "augustus", "september", "oktober", "november", "december"} }
};
tcYear.ItemsSource = calendar;
List<Verplaatsing> Verplaatsingen = new List<Verplaatsing>
{
new Verplaatsing() { Datum = new DateTime(2018, 2, 5), KmAuto = 1 },
new Verplaatsing() { Datum = new DateTime(2018, 2, 15), KmAuto = 2 },
new Verplaatsing() { Datum = new DateTime(2018, 2, 25), KmAuto = 3 }
};
dgVerplaatsingen.ItemsSource = Verplaatsingen ;
dgVerplaatsingen.ItemsSource = Verplaatsingen;
推荐答案
这篇关于在使用itemssource之前,items集合必须为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!