2017-03-12 6 views
2

キャンバスに18個のテキストボックスを均等に広げたいと思います。ただし、プロパティのTextBoxは設定されていません(これらはすべてキャンバスの左側に表示されます)。このコードはなぜ機能しないのですか?キャンバスにテキストボックスを配置する

<DataGridTemplateColumn.CellTemplate> 
    <DataTemplate> 
     <ItemsControl ItemsSource="{Binding Months}"> <!-- This is a collection of 18 DateTime values --> 
      <ItemsControl.ItemsPanel> 
       <ItemsPanelTemplate> 
        <Canvas Width="{Binding ActualWidth, ElementName=coPlanung}" Background="Aqua" Height="30" Margin="0"/> 
       </ItemsPanelTemplate> 
      </ItemsControl.ItemsPanel> 
      <ItemsControl.ItemTemplate> 
       <DataTemplate> 
        <Border> 
         <TextBox Text="{Binding Path=Date, StringFormat={}{0:MMM-yyyy}, Mode=OneWay}" > 
          <Canvas.Left> 
           <MultiBinding Converter="{StaticResource d2x}"> <!-- This is a convert calculating the left value for each Date Item --> 
            <Binding Path="Date" Mode="OneWay" /> 
            <Binding Path="ActualWidth" ElementName="coPlanung" Mode="OneWay"/> 
           </MultiBinding> 
          </Canvas.Left> 
         </TextBox> 
        </Border> 
       </DataTemplate> 
      </ItemsControl.ItemTemplate> 
     </ItemsControl> 
    </DataTemplate>       
</DataGridTemplateColumn.CellTemplate> 

答えて

4

のTextBlockは、したがってCanvas.Leftは効果がありません設定、ItemsPanelTemplateでキャンバスのない直接の子ではありません。

は商品コンテナのCanvas.LeftプロパティをバインドセッターとItemContainerStyleを宣言しなければならない(つまり、各項目ごとに作成され、ItemsPanelの子として追加されるのContentPresenter、):

<ItemsControl ...> 
    <ItemsControl.ItemsPanel> 
     <ItemsPanelTemplate> 
      <Canvas .../> 
     </ItemsPanelTemplate> 
    </ItemsControl.ItemsPanel> 
    <ItemsControl.ItemContainerStyle> 
     <Style TargetType="ContentPresenter"> 
      <Setter Property="Canvas.Left"> 
       <Setter.Value> 
        <MultiBinding> 
         ... 
        </MultiBinding> 
       </Setter.Value> 
      </Setter> 
     </Style> 
    </ItemsControl.ItemContainerStyle> 
    <ItemsControl.ItemTemplate> 
     <DataTemplate> 
      ... 
     </DataTemplate> 
    </ItemsControl.ItemTemplate> 
</ItemsControl> 
+0

作品大変ありがとうございます! –

関連する問題