2012-02-27 9 views
0

ViewBoxに何かを配置して、このViewBoxをDataGridTemplateColumn.Allのセルテンプレートに追加したいと考えていました。これはコードの背後で(C#)行われていました。ViewboxをDataGridセルに挿入する

私はラベルでそれを行っているが、私はラベルを使用してViewBox.Theコードを使用したいです:

DataGridTemplateColumn dgtc5 = new DataGridTemplateColumn(); 

      dgtc5.Width = 142; 
      dgtc5.Header = "Page Life Expectancy"; 
      DataTemplate dtemp5 = new DataTemplate(); 
      FrameworkElementFactory fef5 = new FrameworkElementFactory(typeof(Label)); 

Binding b5 = new Binding("PleChart");   
fef5.SetBinding(Label.ContentProperty, b5); 

dtemp5.VisualTree = fef5; 
dgtc5.CellTemplate = dtemp5; 

答えて

2

は、ここに私の答えBinding a DataGrid's CellTemplate content to an Element or a DependencyProperty defined on the templated CustomControlを参照してください。単純にこの

<DataTemplate x:Key="template2"> 
    <Viewbox> 
     <StackPanel Orientation="Horizontal"> 
      <TextBlock Text="Funky: "/> 
      <TextBlock Text="{Binding Path=Test, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type local:CustomControl1}}}"/> 
     </StackPanel> 
    </Viewbox> 
</DataTemplate> 

のようなデータテンプレートを変更

が含まれているテキストは、ビューボックスに合わせて縮小/拡大する原因となります。

それとも単純には、次の操作を行います。

<DataGrid.Columns> 
    <DataGridTemplateColumn Header="Test"> 
     <DataGridTemplateColumn.CellTemplate> 
      <DataTemplate> 
       <Viewbox> 
        <TextBlock Text="{Binding Name}"/> 
       </Viewbox> 
      </DataTemplate> 
     </DataGridTemplateColumn.CellTemplate> 
    </DataGridTemplateColumn> 
</DataGrid.Columns> 
関連する問題