开发者

Display an image in silverlight datagrid

How would i display an image in my silverlight d开发者_运维技巧atagrid from the database using WCF please help. thanks in advance.


like this:

<data:DataGridTemplateColumn Width="25">
    <data:DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <Image Width="20" Stretch="Fill" Source="../Images/img.png" />
        </DataTemplate>
    </data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>


XAML:

         <sdk:DataGridTemplateColumn Header="My Image">
                <sdk:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <Image Height="150" HorizontalAlignment="Left" Margin="3,12,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="200"  Source="{Binding Image1}" />
                    </DataTemplate>
                </sdk:DataGridTemplateColumn.CellTemplate>
            </sdk:DataGridTemplateColumn>
        </sdk:DataGrid.Columns>
    </sdk:DataGrid>

Code Behind

public partial class MainPage: UserControl

{

public MainPage()

{

InitializeComponent();

ObservableCollection MyListItem = new ObservableCollection(); MyListItem.Add(new ListItems {Image1 = new BitmapImage(new Uri ("/SilverlightApplication2;component/Images/Capture.JPG",UriKind.Relative)) });

dataGrid1.ItemsSource = MyListItem;

}

}

public class ListItems

{

public BitmapImage Image1 { get; set; }

}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜