简体   繁体   English

在datagrid行中创建按钮Silverlight

[英]Create Button in datagrid row silverlight

I have the silverlight Datagrid like , 我有Datagrid的Silverlight,

在此处输入图片说明

I need to add one button in Every Row and If I click that button it will redirect to another page with particular row's Name Value.Because I need to show the Name value in the redirected Page. 我需要在每一行添加一个按钮,如果单击该按钮,它会重定向到与特定行的名称 Value.Because我需要显示在页面重定向名称值的另一页。

Am new to Silverlight Application.Need your Guidance. 是Silverlight应用程序的新手。需要您的指导。

Chris is right there are lots of tutorials online however for anyone who gets to this site here is an example. 克里斯是对的,在线上有很多教程,但是对于任何访问此站点的人来说,这都是一个例子。

Your datagrid would look something like this 您的数据网格看起来像这样

<sdk:DataGrid AutoGenerateColumns="False" Padding="15" Height="129" x:Name="dgSOF" Width="1021" ItemsSource="{Binding Path=TestListBinding}" RowHeight="30" BorderBrush="#FFE4E4E4">
            <sdk:DataGrid.Columns>
                <sdk:DataGridTextColumn Binding="{Binding Path=Something}" Header="Something"/>
                <sdk:DataGridTemplateColumn>
                    <sdk:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Button Margin="5" Click="Button_Click" Width="100" Content="Click Me!"/>
                        </DataTemplate>
                    </sdk:DataGridTemplateColumn.CellTemplate>
                </sdk:DataGridTemplateColumn>
            </sdk:DataGrid.Columns>
        </sdk:DataGrid>

And then the code behind would look something like this 然后后面的代码看起来像这样

private void Button_Click(object sender, RoutedEventArgs e)
    {
        string ClickedSomething = ((TestSL.TT)(((System.Windows.Controls.ContentPresenter)(VisualTreeHelper.GetParent(sender as Button))).DataContext)).Something;

        SilverlightMessageBoxLibrary.CustomMessage cm = new SilverlightMessageBoxLibrary.CustomMessage("You clicked on " + ClickedSomething, SilverlightMessageBoxLibrary.CustomMessage.MessageType.Error);

        cm.Show();
    }

This should point you in the right direction 这应该为您指明正确的方向

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM