Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# wpf datagridcell元素可见性_C#_Wpf_Xaml - Fatal编程技术网

C# wpf datagridcell元素可见性

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; 使

当鼠标位于datagrid中的行上方时,是否可以更改celltemplate中的按钮可见性。例如,当
MouseIsOver=True
visibility
True
时,
MouseIsOver=False
visibility
False
。我应该使用什么触发器?**

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;}
公共数据()
{
项目=新列表();
项目。添加(“第一”);
项目。添加(“第二项”);
项目。添加(“第三项”);
}
}
}
  • *

如果您的按钮被隐藏,则无法悬停

在Visual studio或Blend中,更改按钮的样式/模板以使ContentPresenter不可见:

在窗口中放置一个临时按钮,右键单击“编辑样式”/“编辑副本”。
将样式命名为“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>