开发者

Hyperlink Button in SilverLight Datagrid

I have read a couple articles but I am still a bit confused. How can I make the first column of each row a hyperlink. I have a field with a number and that number attached to a url pulls up the page of this item. I just want to have the button be dynamically created开发者_高级运维 when I fill the datagrid.


I do this in Telerik RadGridView, but I think the same can be used on the regular DataGrid. I create a DataTemplate containing the column:

var dataTemplate = @"<DataTemplate xmlns=""http://schemas.microsoft.com/client/2007"" xmlns:NimbusControls=""http://schemas.nectar.inf.br/2010/xaml"">
                                    <Border Background=""Transparent"">
                                        <StackPanel Orientation=""Horizontal""
                                                    HorizontalAlignment=""Center"">
                                            <Button Command=""{Binding EditCommand}"" CommandParameter=""{Binding}"" />
                                            <Button Style=""{StaticResource GridDeleteButtonStyle}"" />
                                        </StackPanel>
                                    </Border>
                                </DataTemplate>";

Then you add it to the grid, in Telerik I do the following way:

nimbusDataGrid.Columns.Add(new GridViewColumn
    {
        CellTemplate = (DataTemplate)XamlReader.Load(dataTemplate)
    });

But I think it is easy to reproduce in DataGrid.

Another path is to create the command in the object you are using as ItemsSource, and creating a Template for it that generates the Hyperlink column.

Hope it helps.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜