1. 程式人生 > 其它 >wpf中datagrid中的資料向外層viewmodel中繫結資料

wpf中datagrid中的資料向外層viewmodel中繫結資料

<DataGridTemplateColumn Header="操作" Width="*" SortMemberPath="ModificateDate" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button Style="{StaticResource noborderbtnStyle}" Foreground="Blue" Content="修改" Command="{Binding DataContext.DoubleClickCommand,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=UserControl}}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}, Path=SelectedItem}"/>
<Button Content="刪除" Command="{Binding DataContext.DeleteRoleCommand,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=UserControl}}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}, Path=SelectedItem}"/>
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

--禁止轉載