小编Dav*_*mer的帖子

自动大写WPF中的所有输入

有没有办法自动大写所有输入思考WPF应用程序?

wpf input uppercase

21
推荐指数
1
解决办法
2万
查看次数

如何在WPF中的Button上禁用MouseOver效果?

我试图在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中,我认为会覆盖所有默认行为.但事实并非如此.

有什么建议?

wpf styles button mouseevent

21
推荐指数
1
解决办法
4万
查看次数

JLabel或JTable单元格上的ActionListener

我有一个JTable JLabel[][]作为数据.现在我想检测双击JLabel或表格单元格(但只在其中一列中).如何在JLabel表格单元格上添加Action/MouseListener?

java swing jtable mouseevent actionlistener

21
推荐指数
2
解决办法
5万
查看次数

WPF DataGrid样式 - Silverlight DataGrid?

这不是秘密:Silverlight的DataGrid默认风格很漂亮而WPF很差.

让我向社区询问是否有人复制了SL样式以在WPF中使用,而不是重新发明轮子.

请查看截图并自行判断Silverlight和WPF团队如何投资他们的产品.

Silverlight默认样式的DataGrid:

Silverlight DataGrid

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

silverlight wpf datagrid styling wpftoolkit

21
推荐指数
3
解决办法
1万
查看次数

将ListBoxItem的IsSelected属性绑定到该对象的源上的属性

我有一个WPF ListBox控件,我将其设置ItemsSource为项目对象的集合.如何将对象的IsSelected属性绑定ListBoxItemSelected相应项对象的属性,而不将对象的实例设置为Binding.Source

data-binding wpf selected listboxitem

21
推荐指数
1
解决办法
2万
查看次数

以编程方式从addins获取当前的Visual Studio IDE解决方案目录

我有一些工具可以在.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)

c# solution visual-studio envdte vs-extensibility

21
推荐指数
2
解决办法
3万
查看次数

WPF包装面板和滚动

我有一个简单的WrapPanel包含许多宽控件.当我调整大小Width时,Window一切按预期工作.如果有足够的空间,控件将在一行上进行,或者如果没有,则控件将在下一行中包含.

但是,我需要发生的是,如果所有控件基本上都是垂直堆叠的(因为没有更多的水平空间)并且其中WidthWindow更多还是更多,则会出现一个水平滚动条,以便我可以滚动并查看整个控制我是否愿意.下面是我的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)

c# wpf scroll wrappanel

21
推荐指数
2
解决办法
5万
查看次数

为什么每次双击都会多次引发TreeViewItem的MouseDoubleClick事件?

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次.此外,所有的事件参数参数也是相同的,所以我无法区分最后一个参数.

任何想法为什么这是它的方式?

wpf treeview mouseevent treeviewitem

21
推荐指数
5
解决办法
1万
查看次数

21
推荐指数
4
解决办法
1万
查看次数

将WPF样式应用于多个控件

这个问题可能是重复的,但我在SO上找不到它.

如果我有一个容器Window,StackPanel,Grid等有没有什么办法可以应用Style到包含在其中的某一类型的所有控件?

我可以通过使用Container.Resources和设置个别更改来应用属性更改,TargetType但是当我尝试设置Style目标时,我收到错误,告诉我无法设置Style.

有没有办法在XAML中这样做?

.net xaml styles wpf-controls

21
推荐指数
1
解决办法
2万
查看次数