RadButton in DataTemplate in ListView

2 posts, 0 answers
  1. Jon
    Jon avatar
    539 posts
    Member since:
    Apr 2004

    Posted 15 May 2012 Link to this post

    I have RadButton in a DataTemplate in a ListView. I have a command bound to the button that works fine.
    But when I click my button, without selecting the row - i need to get the current row - how can I get the SelectedItem of the current ListView Row when the RadButton is clicked.   For example I want to name the Button REMOVE and remove the current row - without having to click 'behind' the RadButton to select the row to be deleted. first.




    ListView x:Name="lstRangeColors" Width="225" MaxHeight="275" ScrollViewer.VerticalScrollBarVisibility="Visible" Margin="0,0,0,0" ItemsSource="{Binding Path=Filters.RangeColors}" SelectedItem="{Binding Path=RangeColor}">









    <ContentPresenter Margin="5,5,5,5" Content="{Binding}">









    <Grid x:Name="gridContent" Height="35" VerticalAlignment="Stretch">






    <ColumnDefinition Width="20*"/>



    <ColumnDefinition Width="60*"/>



    <ColumnDefinition Width="40*"/>









    <RowDefinition Height="30" />






    <CheckBox Grid.Row="0" Grid.Column="0" Width="40" IsChecked="{Binding RangeValue.IsSelected, Mode=TwoWay}" Margin="5,5,0,0"/>



    <TextBox Grid.Row="0" Grid.Column="1" BorderBrush="Navy" BorderThickness="1" Width="40" Text="{Binding RangeValue, Mode=TwoWay}" Margin="15,0,0,0" FontSize="14" />



    <<telerik:RadButton Grid.Row="0" Grid.Column="2" Height="30" Background="{Binding BlockColor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListView}, Path=DataContext.SelectColorCommand}" HorizontalAlignment="Left" Margin="25,0,0,0" Name="btnColor" Width="40" />






















  2. Zarko
    Zarko avatar
    755 posts

    Posted 18 May 2012 Link to this post

    Hi Jon,
    If you want to remove the row with command you can send the business object as CommandParameter:
    <telerik:RadButton Name="btnColor"
                        Background="{Binding BlockColor,
                        Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListView}, Path=DataContext.SelectColorCommand}"
    CommandParameter="{Binding }" />
    I've attached a sample project that shows this so could you please examine it and if you have further questions feel free to ask.

    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft R3 2016 release webinar banner
Back to Top