【问题标题】:Button Visibilty inside a Datagrid数据网格中的按钮可见性
【发布时间】:2012-08-15 19:41:37
【问题描述】:

我在 WPF 中创建了一个 Datagrid 控件。我怎样才能让我的按钮只对单元格可见

在我选择它的行内。 任何人都可以提供帮助。

XAML:
<DataGridTemplateColumn x:Name="typ" Header="H." Width="50">
  <DataGridTemplateColumn.CellTemplate>
    <DataTemplate>
     <Button Name="btnTabelle" Visibility="Hidden" Height="20" Width="25" 
             Click="Button_Table_Click">

     </Button>
   </DataTemplate>
  </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

【问题讨论】:

标签: c# wpf datagrid wpfdatagrid


【解决方案1】:

您可以根据DataGridCell.IsSelected 设置可见性,尽管您需要BooleanToVisibilityConverter 将布尔值转换为Visibility 一个

这是一个示例,使用RelativeSource 绑定来查找DataGridCell

 <Button Visibility="{Binding Path=IsSelected,
             RelativeSource={RelativeSource AncestorType={x:Type DataGridCell}},
             Converter={StaticResource MyBooleanToVisibiltyConverter}" ... />

【讨论】:

  • 感谢您的解决方案,现在我的按钮在我选择一行时可见,问题是该按钮只有在我选择一行然后按下我在功能区中定义的按钮时才可见Tab 之后我的按钮应该是可见的
  • @User1979 在这种情况下,您需要创建自己的IMultiValueConverter,因为您的可见性将基于两个数据绑定值而不是 1
猜你喜欢
  • 2013-09-26
  • 1970-01-01
  • 2011-04-27
  • 2013-06-14
  • 2013-08-10
  • 1970-01-01
  • 2012-06-15
  • 2011-06-14
  • 2010-12-23
相关资源
最近更新 更多