小编Dav*_*vid的帖子

如何仅在xaml中设置自动对焦?

是否可以将自动对焦设置为我的xaml文件中的文本框?

<Window x:Class="WpfApplication1.Views.Test1"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Height="100"
            Width="210"
            WindowStartupLocation="CenterOwner"
            ShowInTaskbar="False"
            Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"
            ResizeMode="CanResizeWithGrip">
    <TextBox HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Visible" TextWrapping="Wrap" AcceptsReturn="True" Text="{Binding Path=Text, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</Window>
Run Code Online (Sandbox Code Playgroud)

wpf xaml textbox autofocus

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

元素被禁用时按钮上的灰色图像(简单而美观)

当按钮被禁用时,我希望灰显我的图像(在按钮上).当我在按钮上有文本(没有图像)时,文本显示为灰色(将图像作为按钮内容,它们不会变灰).有没有简单而美丽的方法呢?

这是我的xaml文件:

<Window x:Class="WpfApplication2.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <ToolBarTray VerticalAlignment="Top" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" IsLocked="true" Grid.Row="0">
            <ToolBar Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" Band="1" BandIndex="1">
                <Button Command="{Binding Button1}" RenderOptions.BitmapScalingMode="NearestNeighbor">
                    <Button.Content>
                        <Image Source="open.ico"></Image>
                    </Button.Content>
                </Button>
                <Button Command="{Binding Button2}" RenderOptions.BitmapScalingMode="NearestNeighbor">
                    <Button.Content>
                        <Image Source="open.ico"></Image>
                    </Button.Content>
                </Button>
            </ToolBar>
        </ToolBarTray>
    </Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)

这是我的代码隐藏文件:

public partial class MainWindow : Window
{
    private RelayCommand _button1;
    private RelayCommand _button2;

    public MainWindow()
    {
        InitializeComponent();
        DataContext = this;
    }

    public ICommand Button1
    {
        get
        { …
Run Code Online (Sandbox Code Playgroud)

wpf xaml command image button

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

ElementHost中的Application.Current为null

我在我的个人Libs中使用WPF UserControl.Libs包含在我的WPF和WindowsForms程序中.现在我的UserControl必须显示一个新的(WPF)窗口.在新窗口我想设置所有者.我是这样做的:

dialog.Owner = Application.Current.MainWindow;
Run Code Online (Sandbox Code Playgroud)

如果我在WPF程序中使用UserControl,这可以正常工作.

当我在我的WindowsForms程序中使用UserControl时(我在ElementHost中设置UserControl elementHost.Child = ...)为Application.Currentnull.

这不好,我的程序抛出异常.

为什么是Application.Currentnull?

windows user-controls elementhost winforms

16
推荐指数
1
解决办法
7853
查看次数

来自Angular的HTTP请求以OPTIONS而非POST的形式发送

我试图将一些HTTP请求从我的angular.js应用程序发送到服务器,但是我需要解决一些CORS错误。

使用以下代码发出HTTP请求:

functions.test = function(foo, bar) {
    return $http({
        method: 'POST',
        url: api_endpoint + 'test',
        headers: {
            'foo': 'value',
            'content-type': 'application/json'
        },
        data: {
            bar:'value'
        }
    });
};
Run Code Online (Sandbox Code Playgroud)

第一次尝试以一些CORS错误结束。因此,我在PHP脚本中添加了以下几行:

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE, PUT');
header('Access-Control-Allow-Headers: X-Requested-With, Content-Type, Origin, Authorization, Accept, Client-Security-Token, Accept-Encoding, X-Auth-Token, content-type');
Run Code Online (Sandbox Code Playgroud)

现在消除了第一个错误。

现在,Chrome的开发者控制台向我显示以下错误:

angular.js:12011选项http:// localhost:8000 / test(匿名函数)

423ef03a:1 XMLHttpRequest无法加载 http:// localhost:8000 / test。飞行前的响应具有无效的HTTP状态代码400

并且网络请求看起来像我预期的那样(HTTP状态400也是预期的):

网络请求

我无法想象如何解决问题(以及如何理解),为什么请求将在localhost OPTIONS和上发送到远程服务器POST。有解决方案如何解决这个奇怪的问题?

javascript php http cors angularjs

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

如何用反射调用泛型扩展方法?

我写了扩展方法GenericExtension.现在我想调用扩展方法Extension.但是值methodInfo始终为null.

public static class MyClass
{
    public static void GenericExtension<T>(this Form a, string b) where T : Form
    {
        // code...
    }

    public static void Extension(this Form a, string b, Type c)
    {
        MethodInfo methodInfo = typeof(Form).GetMethod("GenericExtension", new[] { typeof(string) });
        MethodInfo methodInfoGeneric = methodInfo.MakeGenericMethod(new[] { c });
        methodInfoGeneric.Invoke(a, new object[] { a, b });
    }

    private static void Main(string[] args)
    {
        new Form().Extension("", typeof (int));
    }
}
Run Code Online (Sandbox Code Playgroud)

怎么了?

c# generics extension-methods methodinfo

10
推荐指数
1
解决办法
6408
查看次数

PasswordBox不承担样式

我有以下样式定义:

<!-- Border -->
<Style x:Key="MyControlBorder" TargetType="{x:Type Border}">
    <Setter Property="BorderBrush" Value="DarkKhaki" />
    <Setter Property="Background" Value="White" />
    <Setter Property="BorderThickness" Value="1" />
    <Setter Property="CornerRadius" Value="10" />
</Style>

<!-- TextBox -->
<Style x:Key="MyTextBox" TargetType="{x:Type TextBox}">
    <Setter Property="Height" Value="30" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type TextBoxBase}">
                <Border Name="TextBoxBorder" Style="{StaticResource MyControlBorder}">
                    <ScrollViewer x:Name="PART_ContentHost"/>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

<!-- PasswordBox -->
<Style x:Key="MyPasswordBox" TargetType="{x:Type PasswordBox}">
    <Setter Property="Height" Value="30" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Control}">
                <Border Name="Border" Style="{StaticResource MyControlBorder}">
                    <ScrollViewer x:Name="PART_ContentHost" />
                </Border>
            </ControlTemplate>
        </Setter.Value> …
Run Code Online (Sandbox Code Playgroud)

wpf xaml styles passwordbox controltemplate

9
推荐指数
1
解决办法
2445
查看次数

使用多个大小的值对字典进行排序

我有一本需要排序的字典.我知道字典无法排序,所以我正在构建一个列表来执行基于索引的排序.我遇到的问题是多个键上有重复的值; 此外,值可以是多个列表.

字典:

my_dict = {
    '1' : ['Red', 'McDonald\'s'],
    '2' : [['Orange', 'Wendy\'s'], ['Purple', 'Cookout']],
    '3' : ['Yellow', 'Longhorn'],
    '4' : ['Green', 'Subway'],
    '5' : ['Blue', 'Chipotle'],
    '6' : ['Indigo', 'Taco Bell'],
    '7' : [['Violet', 'Steak n Shake'], ['Dark Red', 'Five Guys']],
    '8' : ['Dark Orange', 'Wendy\'s'],
    '9' : ['Aqua', 'Firehouse Subs'],
    '10' : ['Magenta', 'McDonald\'s'],
}
Run Code Online (Sandbox Code Playgroud)

我需要能够通过键(数字),颜色和餐厅对其进行排序.我遇到的问题是,当存在重复时,必须对打印进行分组,而我无法弄清楚如何对我正确生成的列表进行排序.

按编号打印的示例:

1:
    Red, McDonald's

2:
    Orange, Wendy's
    Purple, Cookout

3:
    Yellow, Longhorn

...
Run Code Online (Sandbox Code Playgroud)

按颜色打印的示例:

Aqua:
    Firehouse Subs, 9

Blue:
    Chipotle, 5 …
Run Code Online (Sandbox Code Playgroud)

python sorting dictionary loops python-3.x

9
推荐指数
1
解决办法
160
查看次数

在 nuxt 中排除 webpack 中的文件

我已将一些文件添加到我的 nuxt 项目中。文件存储在./content目录中。现在我们收到了一些警告,如下所示:

WARN  in ./content/config.yml

Module parse failed: Unexpected token (9:9)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
Run Code Online (Sandbox Code Playgroud)

为了防止出现错误,我尝试排除nuxt.config.js. 我添加了以下几行,但警告并没有消失。

build: {
  /*
  ** You can extend webpack config here
  */
  extend (config, ctx) {
    config.module.rules.push({
      test: /\.yml$/,
      exclude: [
        path.resolve(__dirname, '/content/config.yml')
      ]
    }
  )
  }
}
Run Code Online (Sandbox Code Playgroud)

还有其他选项可以防止出现警告吗?

webpack vue.js nuxt.js

9
推荐指数
0
解决办法
889
查看次数

strlen()== 0和empty()之间有区别吗?

我正在查看其他人写过的表格验证码,我看到了这个:

strlen() == 0
Run Code Online (Sandbox Code Playgroud)

在测试表单变量是否为空时,我使用该empty()函数.有一种方式比另一种更好吗?它们在功能上是否相同?

php strlen

8
推荐指数
3
解决办法
8533
查看次数

作曲家:一个回购中的多个包

我有一个GIT-Repo里面有我所有的模块.我想使用Composer将它们包含在我的不同项目中.有没有办法将它们全部放在一个git仓库中,还是我需要为每个模块创建一个自己的GIT-Repo?

git composer-php

7
推荐指数
1
解决办法
2937
查看次数