我想使用以下代码在数据网格的列标题中绘制线条。有两个ItemsControl
都绑定到包含18个日期的集合(每个月的第一个)。转换器按日期计算列标题中的位置,以便将控件放在列标题中。
<DataGridTemplateColumn Width="1*" x:Name="coPlanung">
<DataGridTemplateColumn.HeaderTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<!--Monatsnamen-->
<ItemsControl Grid.Row="0" ItemsSource="{Binding DataContext.Monate, ElementName=dgBaustellen}" Margin="0" VerticalAlignment="Center" HorizontalAlignment="Left" Background="LightBlue">
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="Canvas.Left">
<Setter.Value>
<MultiBinding Converter="{StaticResource d2x}">
<Binding Path="Date" Mode="OneWay" />
<Binding Path="ActualWidth" ElementName="coPlanung" Mode="OneWay"/>
</MultiBinding>
</Setter.Value>
</Setter>
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas Width="{Binding ActualWidth, ElementName=coPlanung}" Margin="-5,0,0,0" Background="LemonChiffon"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<!--Monatsnamen-->
<Border BorderThickness="1,0,1,0" BorderBrush="Black">
<TextBox Text="{Binding Path=Date, StringFormat={}{0:MMM-yyyy}, Mode=OneWay}"
HorizontalAlignment="Center" VerticalAlignment="Center" HorizontalContentAlignment="Center"
Background="Transparent" Margin="0" BorderThickness="0">
<TextBox.Width>
<MultiBinding Converter="{StaticResource d2b}">
<Binding Path="Date" Mode="OneWay" />
<Binding Path="ActualWidth" ElementName="coPlanung" Mode="OneWay"/>
</MultiBinding>
</TextBox.Width>
</TextBox>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<!--Linien-->
<ItemsControl Grid.Row="1" ItemsSource="{Binding DataContext.Monate, ElementName=dgBaustellen}" >
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="Canvas.Left">
<Setter.Value>
<MultiBinding Converter="{StaticResource d2x}">
<Binding Path="Date" Mode="OneWay" />
<Binding Path="ActualWidth" ElementName="coPlanung" Mode="OneWay"/>
</MultiBinding>
</Setter.Value>
</Setter>
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas Width="{Binding ActualWidth, ElementName=coPlanung}" Margin="-5,0,0,0" Background="LemonChiffon"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<!--Linien-->
<Line Y1="-10" Y2="30" Stroke="Red" >
<Line.X1>
<MultiBinding Converter="{StaticResource d2x}" >
<Binding Path="Date" Mode="OneWay" />
<Binding Path="ActualWidth" ElementName="coPlanung" Mode="OneWay"/>
</MultiBinding>
</Line.X1>
<Line.X2>
<MultiBinding Converter="{StaticResource d2x}">
<Binding Path="Date" Mode="OneWay" />
<Binding Path="ActualWidth" ElementName="coPlanung" Mode="OneWay"/>
</MultiBinding>
</Line.X2>
</Line>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</DataTemplate>
</DataGridTemplateColumn.HeaderTemplate>
显然,我想要的是在月份名称之间的黑线上画一条红线。看起来只有每一条线都被绘制出来。
有人有想法解决这个问题吗?