C# wpf datagridcell元素可见性
当鼠标位于datagrid中的行上方时,是否可以更改celltemplate中的按钮可见性。例如,当C# wpf datagridcell元素可见性,c#,wpf,xaml,C#,Wpf,Xaml,当鼠标位于datagrid中的行上方时,是否可以更改celltemplate中的按钮可见性。例如,当MouseIsOver=TruevisibilityTrue时,MouseIsOver=FalsevisibilityFalse。我应该使用什么触发器?** Xaml: 好啊 代码: 使用系统; 使用System.Collections.Generic; 使用System.Linq; 使用系统文本; 使用System.Windows; 使用System.Windows.Controls; 使
MouseIsOver=True
visibilityTrue
时,MouseIsOver=False
visibilityFalse
。我应该使用什么触发器?**
Xaml:
好啊
代码:
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Data;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Imaging;
使用System.Windows.Navigation;
使用System.Windows.Shapes;
命名空间WpfApplication3
{
///
///MainWindow.xaml的交互逻辑
///
公共部分类主窗口:窗口
{
公共主窗口()
{
初始化组件();
DataContext=新数据();
}
}
公共类结构
{
公共字符串名称{get;set;}
}
公共类数据
{
公共列表项{get;set;}
公共数据()
{
项目=新列表();
项目。添加(“第一”);
项目。添加(“第二项”);
项目。添加(“第三项”);
}
}
}
- *
将样式命名为“InvisibleButtonStyle” 在触发器部分,添加:
<Trigger Property="IsMouseOver" Value="false">
<Setter Property="Background" TargetName="border" Value="Transparent"/>
<Setter Property="BorderBrush" TargetName="border" Value="Transparent"/>
<Setter Property="Foreground" Value="Transparent"/>
</Trigger>
然后销毁临时按钮,并将样式应用于DataGrid按钮:
<Button Style="{StaticResource InvisibleButtonStyle}">OK</Button>
OK
就这样,快乐编码@A191919,如果有什么问题,请告诉我。我做了一个小演示,如果需要的话我可以发送给你。当做
<Trigger Property="IsMouseOver" Value="false">
<Setter Property="Background" TargetName="border" Value="Transparent"/>
<Setter Property="BorderBrush" TargetName="border" Value="Transparent"/>
<Setter Property="Foreground" Value="Transparent"/>
</Trigger>
<Button Style="{StaticResource InvisibleButtonStyle}">OK</Button>