小编Jos*_*ant的帖子

WPF ListView非活动选择颜色

我正在创建一个WPF应用程序,其中连续生成多个ListView选项(类似于iTunes浏览器).问题是默认的非活动选择颜色太浅.(见下文) 默认非活动选择颜色(太亮)

如何更改此颜色,以便我的非活动列表视图如下所示?(见下文) 非活动和主动选择颜色相同

使用Style类似的方法覆盖默认的SystemColor :

<Style TargetType="ListViewItem">
    <Style.Resources>
        <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="{x:Static SystemColors.HighlightColor}"/>
    </Style.Resources>
</Style>
Run Code Online (Sandbox Code Playgroud)

wpf listview selection

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

WPF UserControl设计时间大小

在WPF中创建UserControl时,我发现给它一些任意的Height和Width值很方便,这样我就可以在Visual Studio设计器中查看我的更改.但是,当我运行控件时,我希望高度和宽度未定义,以便控件将展开以填充我放入的任何容器.如何在不必删除高度和宽度值之前实现相同的功能建立我的控制?(或者不在父容器中使用DockPanel.)

以下代码演示了此问题:

<Window x:Class="ExampleApplication3.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:loc="clr-namespace:ExampleApplication3"
    Title="Example" Height="600" Width="600">
    <Grid Background="LightGray">
        <loc:UserControl1 />
    </Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)

以下定义UserControl1在设计时合理显示,但在运行时显示为固定大小:

<UserControl x:Class="ExampleApplication3.UserControl1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="300" Width="300">
    <Grid Background="LightCyan" />
</UserControl>
Run Code Online (Sandbox Code Playgroud)

以下定义UserControl1在设计时显示为点,但Window1在运行时展开以填充父级:

<UserControl x:Class="ExampleApplication3.UserControl1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Grid Background="LightCyan" />
</UserControl>
Run Code Online (Sandbox Code Playgroud)

wpf user-controls autosize

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

等于(item,null)或item == null

使用静态Object.Equals检查null的代码是否比使用==运算符或常规Object.Equals的代码更健壮?是不是后两种易受这样一种方式,检查空预期不工作正在被超越(如返回false时,比较值零)?

换句话说,是这样的:

if (Equals(item, null)) { /* Do Something */ }
Run Code Online (Sandbox Code Playgroud)

比这更强大:

if (item == null) { /* Do Something */ }
Run Code Online (Sandbox Code Playgroud)

我个人觉得后面的语法更容易阅读.编写处理作者控件之外的对象的代码(例如库)时应该避免吗?是否应始终避免(检查为空时)?这只是头发分裂吗?

c# null equals robustness

39
推荐指数
3
解决办法
4万
查看次数

保存之前的WPF Databind

在我的WPF应用程序中,我有许多数据绑定TextBoxes.在UpdateSourceTrigger这些绑定的LostFocus.使用"文件"菜单保存对象.我遇到的问题是可以在TextBox中输入一个新值,从File菜单中选择Save,并且永远不会保留新值(TextBox中可见的值)因为访问菜单不会从TextBox中删除焦点.我怎样才能解决这个问题?有没有办法强制页面中的所有控件数据绑定?

@palehorse:好点.不幸的是,我需要使用LostFocus作为我的UpdateSourceTrigger,以支持我想要的验证类型.

@dmo:我想到了这一点.然而,对于一个相对简单的问题,它似乎是一个非常不优雅的解决方案.此外,它要求页面上有一些控件,它始终可见以接收焦点.然而,我的应用程序是标签,因此没有这样的控件容易出现.

@Nidonocu:使用菜单没有从TextBox移动焦点的事实也使我感到困惑.然而,这就是我所看到的行为.以下简单示例演示了我的问题:

<Window x:Class="WpfApplication2.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Window.Resources>
        <ObjectDataProvider x:Key="MyItemProvider" />
    </Window.Resources>
    <DockPanel LastChildFill="True">
        <Menu DockPanel.Dock="Top">
            <MenuItem Header="File">
                <MenuItem Header="Save" Click="MenuItem_Click" />
            </MenuItem>
        </Menu>
        <StackPanel DataContext="{Binding Source={StaticResource MyItemProvider}}">
            <Label Content="Enter some text and then File > Save:" />
            <TextBox Text="{Binding ValueA}" />
            <TextBox Text="{Binding ValueB}" />
        </StackPanel>
    </DockPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)
using System;
using System.Text;
using System.Windows;
using System.Windows.Data;

namespace WpfApplication2
{
    public partial class Window1 : Window
    {
        public MyItem Item
        {
            get …
Run Code Online (Sandbox Code Playgroud)

data-binding wpf

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

哈希表数组的格式表

如何使用Format-Table cmdlet 格式化哈希表数组?

例:

$table = @( @{ColumnA="Able";    ColumnB=1},
            @{ColumnA="Baker";   ColumnB=2},
            @{ColumnA="Charlie"; ColumnB=3} )
$table | Format-Table
Run Code Online (Sandbox Code Playgroud)

期望的输出:

ColumnA                        ColumnB
----                           -----
Able                           1
Baker                          2
Charlie                        3
Run Code Online (Sandbox Code Playgroud)

实际产量:

Name                           Value
----                           -----
ColumnA                        Able
ColumnB                        1
ColumnA                        Baker
ColumnB                        2
ColumnA                        Charlie
ColumnB                        3
Run Code Online (Sandbox Code Playgroud)

powershell formatting

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

公开DependencyProperty

在开发WPF UserControls时,将子控件的DependencyProperty公开为UserControl的DependencyProperty的最佳方法是什么?以下示例显示了我当前如何在UserControl中公开TextBox的Text属性.当然有更好/更简单的方法来实现这一目标?

<UserControl x:Class="WpfApplication3.UserControl1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <StackPanel Background="LightCyan">
        <TextBox Margin="8" Text="{Binding Text, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" />
    </StackPanel>
</UserControl>


using System;
using System.Windows;
using System.Windows.Controls;

namespace WpfApplication3
{
    public partial class UserControl1 : UserControl
    {
        public static DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(UserControl1), new PropertyMetadata(null));
        public string Text
        {
            get { return GetValue(TextProperty) as string; }
            set { SetValue(TextProperty, value); }
        }

        public UserControl1() { InitializeComponent(); }
    }
}
Run Code Online (Sandbox Code Playgroud)

data-binding wpf user-controls

18
推荐指数
1
解决办法
8196
查看次数

Visual Studio使用SCP/SFTP发布网站

有没有办法使用SCP或SFTP从Visual Studio 2008发布网站?我知道可以发布到我的本地文件系统然后用SCP执行传输,但我想要更无缝的东西(例如Visual Studio的一部分).这个功能是否存在?也许是一个插件?

publishing visual-studio-2008 visual-studio web

14
推荐指数
2
解决办法
7282
查看次数

打开项目属性时Visual Studio 2008崩溃

我有一个多项目.NET应用程序,我在Visual Studio 2008中开发.如果我​​尝试打开我的一个项目的项目属性(更改设置或发布),Visual Studio会立即关闭.没有提示向Microsoft发送报告,并且事件查看器中记录了两个连续错误:

  • .NET运行时版本2.0.50727.3053 - 致命执行引擎错误(7A035E00)(80131506)
  • .NET运行时版本2.0.50727.3053 - 致命执行引擎错误(7A2E0F92)(0)

如果我删除所有.user,并.suo在我的解决方案文件,我可以再次发布和访问项目属性.但是,错误随着时间的推移而返回.这似乎表明,.suo.user文件得到由Visual Studio损坏.有没有其他人有这个问题或知道如何解决这个问题?

crash visual-studio-2008

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

TabControl底部的选项卡

如何让Tab Control将选项卡放在控件的底部而不是顶部

c# winforms

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

WPF TextBox拦截RoutedUICommands

我试图在我的WPF应用程序中使用Undo/Redo键盘快捷键(我使用命令模式实现了自己的自定义功能).但是,似乎TextBox控件正在拦截我的"撤消"RoutedUICommand.

什么是禁用此功能的最简单方法,以便我可以在UI树的根目录中捕获Ctrl + Z?TextBox如果可能的话,我想避免在我的应用程序中添加大量代码/ XAML .

以下简要说明问题:

<Window x:Class="InputBindingSample.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:loc="clr-namespace:InputBindingSample"
    Title="Window1" Height="300" Width="300">
    <Window.CommandBindings>
        <CommandBinding Command="loc:Window1.MyUndo" Executed="MyUndo_Executed" />
    </Window.CommandBindings>
    <DockPanel LastChildFill="True">
        <StackPanel>
            <Button Content="Ctrl+Z Works If Focus Is Here" />
            <TextBox Text="Ctrl+Z Doesn't Work If Focus Is Here" />
        </StackPanel>
    </DockPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)
using System.Windows;
using System.Windows.Input;

namespace InputBindingSample
{
    public partial class Window1
    {
        public static readonly RoutedUICommand MyUndo = new RoutedUICommand("MyUndo", "MyUndo", typeof(Window1),
            new InputGestureCollection(new[] { new KeyGesture(Key.Z, ModifierKeys.Control) }));

        public …
Run Code Online (Sandbox Code Playgroud)

wpf keyboard-shortcuts undo routed-commands

11
推荐指数
2
解决办法
4962
查看次数