3

The code below is in WPF in .net 4, which shows a grid which is empty in the beginning. When I add elements, it will display the row with progress bar and 'send' button in the last two columns respectively. When I add one more row, one more progress bar and button appears. But if I click the button, all button uses same event handler. How can I make each progress bar and buttons in rows different?

<Window x:Class="ObservableCollection.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <DataGrid Name="DataGrid" ItemsSource="Binding DataGrids" AutoGenerateColumns="False" RowHeight="30"
                  ColumnWidth="100" ColumnHeaderHeight="50" HeadersVisibility="Column" AlternatingRowBackground="LightBlue"
                  CanUserAddRows="False" Background="Transparent" RowBackground="Transparent" BorderBrush="Gray"
                  CellStyle="{StaticResource Body_Conternt_DataGrid_Centering}"
                  IsReadOnly="True" Margin="49,66,45,62" Opacity="1" >
                  <DataGrid.Columns>
            <DataGridTextColumn Width="*" Header="UID" Binding="{Binding Uid}" />
            <DataGridTextColumn Width="*" Header="Type" Binding="{Binding Type}" />
            <DataGridTextColumn Width="*" Header="Channel Type" Binding="{Binding ChannelType}" />
            <DataGridTextColumn Width="*" Header="Certificate" Binding="{Binding Certificate}" />
            <DataGridTextColumn Width="*" Header="Life Cycle State" Binding="{Binding LifeCycle}" />
            <DataGridTextColumn Width="*" Header="Status" Binding="{Binding Status}" />
            <DataGridTextColumn Width="*" Header="Image UID" Binding="{Binding ImageUid}" />

            <DataGridTemplateColumn Width="*">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <ProgressBar Height="20" Value="{Binding Progress}"></ProgressBar>
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>

            <DataGridTemplateColumn Width="*">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <Button Name="btnSend" Click="btnSend_Click">Send</Button>
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>
                </DataGrid.Columns>
        </DataGrid>
    </Grid>
</Window>

2 Answers 2

3

am thinking of binding the Tag property to a unique key of whatever you're trying to send,

<Button Tag="{Binding ID}> 

and on your send event get the tag value back..

var button = sender as Button;
var tag = button.Tag;
Sign up to request clarification or add additional context in comments.

Comments

2

This link may be useful, where it is described how you can get the rownumber when clicking on a button in a datagrid column

WPF DataGrid - Button in a column, getting the row from which it came on the Click event handler

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.