我試圖創建在Silverlight的用戶中,我想展示自己的形象,名稱的列表,分數等將圖像添加到Silverlight中的DataGrid行?
我用這個代碼來繪製一個DataGrid,這樣我看起來像一個列表:
<sdk:DataGrid Grid.Row="1" x:Name="KitchenChart" HorizontalAlignment="Center" AutoGenerateColumns="False" ItemsSource="{Binding KitchenScore}" Background="Black"
AlternatingRowBackground="Black" GridLinesVisibility="Horizontal">
<sdk:DataGrid.Columns>
<sdk:DataGridTemplateColumn Header="Image" IsReadOnly="True">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Background="Black">
<Image Source="{Binding Image}" />
</StackPanel>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
<sdk:DataGridTemplateColumn Header="Name">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Background="Black">
<TextBlock Padding="5,0,5,0" Text="{Binding Name}" Foreground="White"/>
</StackPanel>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
<sdk:DataGridTemplateColumn Header="Score">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Background="Black">
<TextBlock Padding="5,0,5,0" Text="{Binding Score}" Foreground="White" HorizontalAlignment="Stretch"/>
</StackPanel>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
</sdk:DataGrid.Columns>
</sdk:DataGrid>
And the i used class to load dynamic data in datagrid using this as :
public class KitchenScoreClass
{
public Image Image { get; set; }
public string Name { get; set; }
public int Score { get; set; }
public KitchenScoreClass(Image Image, string Name, int Score)
{
this.Image = Image;
this.Name = Name;
this.Score = Score;
}
}
然後我創建了加載dynimically所有數據
private List<KitchenScoreClass> KitchenScore()
{
List<KitchenScoreClass> avgg = new List<KitchenScoreClass>();
avgg.Add(new KitchenScoreClass(??? ,"kundan",10));
avgg.Add(new KitchenScoreClass(??? , "me", 15));
avgg.Add(new KitchenScoreClass(??? , "varun", 10));
return avgg;
}
,並在最後一次使用此功能將數據添加到數據網格KitchenChart作爲一個函數:
public ScoreCharts()
{
InitializeComponent();
KitchenChart.ItemsSource = KitchenScore();
}
但我不知道如何添加圖像?假設我的所有圖像都與我的解決方案文件夾一起存儲在文件夾Mysolution/MyImgs中。 我如何添加圖片?
請幫
感謝
你的圖像存儲在哪裏? – ChrisF 2012-03-09 11:03:36
@ChrisF:剛剛更新... – CracLock 2012-03-09 11:10:50