How can I change the visibility of elements inside a DataTemplate when a row is selected in a Silver

Posted by miketrash on Stack Overflow See other posts from Stack Overflow or by miketrash
Published on 2010-03-24T05:43:27Z Indexed on 2010/03/24 5:53 UTC
Read the original article Hit count: 263

I'm using the MVVM pattern. I've bound my items and I want to only show the edit button when a row is selected in the datagrid. It appears to be possible with triggers in WPF but we don't have triggers in Silverlight. I tried a TemplatedParent binding but I'm not sure what the TemplatedParent is in this case. We don't have RelativeSource ancestor in Silverlight either. At this point I'm going to look at a solution using the code behind...

<data:DataGrid.Columns>
   <data:DataGridTemplateColumn IsReadOnly="True" Header="Name" Width="300">
      <data:DataGridTemplateColumn.CellTemplate>
         <DataTemplate>
            <Grid>
               <TextBlock x:Name="textBlock" Text="{Binding Name, Mode=OneWay}" VerticalAlignment="Center" Margin="4,4,0,4"/>
               <Button  Margin="1,1,4,1" HorizontalAlignment="Right" VerticalAlignment="Center" Padding="7,4" Content="Edit" />
            </Grid>
         </DataTemplate>
       </data:DataGridTemplateColumn.CellTemplate>
   </data:DataGridTemplateColumn>
</data:DataGrid.Columns>

© Stack Overflow or respective owner

Related posts about Silverlight

Related posts about mvvm