我试图在WPF中禁用按钮上的MouseOver效果,或者至少更改它的颜色.
我使用以下样式:
<Style x:Key="Borderless" TargetType="{x:Type Button}">
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Button Background="{TemplateBinding Control.Background}"
Focusable="False">
<ContentPresenter
Margin="{TemplateBinding Control.Padding}"
HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}"
ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}"
RecognizesAccessKey="True"
Content="{TemplateBinding ContentControl.Content}" />
</Button>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)
在Window.Resources中,我认为会覆盖所有默认行为.但事实并非如此.
有什么建议?
我有一个JTable JLabel[][]作为数据.现在我想检测双击JLabel或表格单元格(但只在其中一列中).如何在JLabel表格单元格上添加Action/MouseListener?
这不是秘密:Silverlight的DataGrid默认风格很漂亮而WPF很差.
让我向社区询问是否有人复制了SL样式以在WPF中使用,而不是重新发明轮子.
请查看截图并自行判断Silverlight和WPF团队如何投资他们的产品.
Silverlight默认样式的DataGrid:

WPF默认样式的DataGrid(在Saied K的回答之后更新):

我有一个WPF ListBox控件,我将其设置ItemsSource为项目对象的集合.如何将对象的IsSelected属性绑定ListBoxItem到Selected相应项对象的属性,而不将对象的实例设置为Binding.Source?
我有一些工具可以在.NET解决方案上执行更新,但是他们需要知道解决方案所在的目录.
我将这些工具添加为外部工具,它们出现在IDE工具菜单中,并$(SolutionDir)作为参数提供.这很好用.
但是,我希望通过自定义顶级菜单(我为其创建Visual Studio集成包项目)以及通过解决方案节点上的上下文菜单(我为其创建了一个Visual),在IDE中为用户更轻松地访问这些工具. Studio加载项目).我正在寻找一种方法来通过这些上下文获取当前的解决方案目录.
我尝试从VisualStudio.DTE对象获取解决方案信息:
EnvDTE.DTE dte = (EnvDTE.DTE)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE");
string solutionDir = System.IO.Path.GetDirectoryName(dte.Solution.FullName);
Run Code Online (Sandbox Code Playgroud)
但是,这将返回add ins的解决方案目录,而不是当前解决方案.
我试着回应$(SolutionDir)并回读它:
System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", "echo $(SolutionDir)");
// The following commands are needed to redirect the standard output.
// This means that it will be redirected to the Process.StandardOutput StreamReader.
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
// Do not create the black window.
procStartInfo.CreateNoWindow = true;
// Now we create a process, assign its ProcessStartInfo and start …Run Code Online (Sandbox Code Playgroud) 我有一个简单的WrapPanel包含许多宽控件.当我调整大小Width时,Window一切按预期工作.如果有足够的空间,控件将在一行上进行,或者如果没有,则控件将在下一行中包含.
但是,我需要发生的是,如果所有控件基本上都是垂直堆叠的(因为没有更多的水平空间)并且其中Width的Window更多还是更多,则会出现一个水平滚动条,以便我可以滚动并查看整个控制我是否愿意.下面是我的xaml.我试着把它包裹起来WrapPanel,ScrollViewer但我无法实现我的目标.
<Window x:Class="WpfQuotes.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="Auto" Width="600" Foreground="White">
<WrapPanel>
<Button Width="250">1</Button>
<Button Width="250">2</Button>
<Button Width="250">3</Button>
</WrapPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)
因此,如果Width将上述内容减少Window到最小值,您将无法看到按钮的文本.我想要一个水平滚动条出现,以便我可以滚动查看文本,但不会干扰通常的包装功能.
谢谢.
更新:
我已按照下面的保罗建议,水平滚动条现在按预期显示.但是,我也希望垂直滚动可用,所以我设置VerticalScrollBarVisibility="Auto".问题是,如果我调整窗口大小以便显示垂直滚动条,即使不需要(也有足够的水平空间来查看整个控件),也会始终显示水平滚动条.好像出现的垂直滚动条会弄乱滚动查看器的宽度.有没有办法纠正这个问题,除非实际需要水平滚动条,否则不会出现?
下面是我的xaml和我添加的唯一代码CustomWrapPanel:
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cwp="clr-namespace:CustomWrapPanelExample"
Title="Window1" Height="Auto" Width="300" Foreground="White" Name="mainPanel">
<ScrollViewer x:Name="MyScrollViewer" HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto">
<cwp:CustomWrapPanel Width="{Binding ElementName=MyScrollViewer, Path=ActualWidth}">
<Button Width="250">1</Button>
<Button Width="250">2</Button>
<Button Width="250">3</Button>
<Button Width="250">4</Button>
<Button Width="250">5</Button>
<Button Width="250">6</Button>
<Button Width="250">7</Button>
<Button Width="250">8</Button> …Run Code Online (Sandbox Code Playgroud) XAML
<TreeView Name="GroupView" ItemsSource="{Binding Documents}">
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<EventSetter Event="MouseDoubleClick" Handler="OnTreeNodeDoubleClick"/>
</Style>
</TreeView.ItemContainerStyle>
....
</TreeView>
Run Code Online (Sandbox Code Playgroud)
代码隐藏
private void OnTreeNodeDoubleClick(object sender, MouseButtonEventArgs mouseEvtArgs)
{
Console.WriteLine("{3} MouseDoubleClick Clicks={0} ChangedButton={1} Source={2} Handled={4} ButtonState={5}",
mouseEvtArgs.ClickCount, mouseEvtArgs.ChangedButton, mouseEvtArgs.OriginalSource,
mouseEvtArgs.Timestamp, mouseEvtArgs.Handled, mouseEvtArgs.ButtonState);
}
Run Code Online (Sandbox Code Playgroud)
我发现只需双击一次,就会多次调用事件处理程序.我试图在选项卡中打开一个文件,双击相应的树节点; 所以我需要过滤掉额外的电话.
23479156 MouseDoubleClick Clicks=1 ChangedButton=Left Source=System.Windows.Controls.TextBlock Handled=False ButtonState=Pressed
23479156 MouseDoubleClick Clicks=1 ChangedButton=Left Source=System.Windows.Controls.TextBlock Handled=False ButtonState=Pressed
Run Code Online (Sandbox Code Playgroud)
在我稍微复杂的应用程序中,每次双击它会被提升4次.在一个简单的repro-app上,每次双击它会被提升2次.此外,所有的事件参数参数也是相同的,所以我无法区分最后一个参数.
任何想法为什么这是它的方式?
这个问题可能是重复的,但我在SO上找不到它.
如果我有一个容器Window,StackPanel,Grid等有没有什么办法可以应用Style到包含在其中的某一类型的所有控件?
我可以通过使用Container.Resources和设置个别更改来应用属性更改,TargetType但是当我尝试设置Style目标时,我收到错误,告诉我无法设置Style.
有没有办法在XAML中这样做?
wpf ×7
c# ×3
mouseevent ×3
styles ×2
xaml ×2
.net ×1
button ×1
data-binding ×1
datagrid ×1
envdte ×1
input ×1
java ×1
jtable ×1
listboxitem ×1
resize ×1
scroll ×1
selected ×1
silverlight ×1
solution ×1
styling ×1
swing ×1
treeview ×1
treeviewitem ×1
uppercase ×1
window ×1
wpf-controls ×1
wpftoolkit ×1
wrappanel ×1