2017-05-17 10 views
0

としてWPF、私は単純なデータグリッドを持つテキスト

のDataGridオブジェクト挿入よ
<DataGrid x:Name="SmartTable"></DataGrid> 

次に、私はコード内の列を初期化し、この構造体にバインド:

public struct HddData 
{ 
    public Ellipse status { set; get; } 
    public string id { set; get; } 
    public string atribute { set; get; } 
    public string current { set; get; } 
    public string worst { set; get; } 
    public string treshhold { set; get; } 
    public string data { set; get; } 
} 

そしてfinaly、私は、foreachのを使用して、テーブルに行を挿入しようとしている:

Ellipse good = new Ellipse(); 
Ellipse bad = new Ellipse(); 
good.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF64DD17")); 
bad.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFD50000")); 
SmartTable.Items.Add(new HddData 
{ 
    status = attr.Value.IsOK ? good : bad, 
    id = attr.Value.id, 
    atribute = attr.Value.Attribute, 
    current = attr.Value.Current.ToString(), 
    worst = attr.Value.Worst.ToString(), 
    treshhold = attr.Value.Threshold.ToString(), 
    data = attr.Value.Data.ToString("X"), 
}); 

テキストデータは罰金結合するが、省略記号は、セル内の文字列の一種であり、このことを示しています。

System.Windows.Shapes.Ellipse 

どのようにテキストとしてではなく楕円として表示できますか?

+2

XAMLを学ぶ、このことは致命的です。 DataGridTemplateColumnが必要です。 –

+0

@EdPlunkett:+1。 majukin:あなたは、あなたのdatagridカラムのいくつかのテンプレートを行う必要があります。 –

答えて

0
public struct HddData 
{ 
    public Brush status { set; get; } 
    public string id { set; get; } 
    public string atribute { set; get; } 
    public string current { set; get; } 
    public string worst { set; get; } 
    public string treshhold { set; get; } 
    public string data { set; get; } 
} 

<DataGridTemplateColumn Header="Status"> 
    <DataGridTemplateColumn.CellTemplate> 
     <DataTemplate> 
      <StackPanel> 
       <Ellipse Fill="{Binding status}" Width="10" Height="10" HorizontalAlignment="Center" VerticalAlignment="Center"/>         
      </StackPanel> 
     </DataTemplate> 
    </DataGridTemplateColumn.CellTemplate> 
</DataGridTemplateColumn> 

Brushが必要です。楕円形を入力してください。

+0

真実のように見えますが、今はセル内に文字列の16進数の色があります:) – makujin

+0

その 'StackPanel'は何ですか? –

+0

'StackPanel'に' textbox'、 'label'などの他のコントロールを含めることができるので、' Ellipse'の隣に別のコントロールを追加することができます。 – KMCho

2

あなたはEllipseEllipseFillプロパティをバインドすることはできません。 CellTemplateContentControlを使用してください。

<DataGridTemplateColumn Header="test"> 
    <DataGridTemplateColumn.CellTemplate> 
     <DataTemplate> 
      <StackPanel> 
       <ContentControl Content="{Binding status}" 
           Width="30" Height="30" 
           HorizontalAlignment="Center" VerticalAlignment="Center"/> 
      </StackPanel> 
     </DataTemplate> 
    </DataGridTemplateColumn.CellTemplate> 
</DataGridTemplateColumn> 
関連する問題