小编jhi*_*man的帖子

使用Viewbox缩放包含标签和文本框的网格

因此,我正在尝试构建一个表单,该表单将根据父容器的可用宽度和相同的列百分比自动按比例上下调整,如下所示:

期望的结果

还有其他周边内容需要扩展,如图像和按钮(不会在同一网格中),从我到目前为止所读到的内容,使用Viewbox是可行的方法.

但是,当我将网格包装在Stretch ="Uniform"的Viewbox中时,Textbox控制每个向下折叠到它们的最小宽度,如下所示: 带有网格和折叠文本框的Viewbox

如果我增加容器宽度,一切都按预期(好)缩放,但文本框仍然折叠到最小可能宽度(坏): 增加宽度

如果我在文本框中键入任何内容,他们将增加其宽度以包含文本: 文本框展开以适合内容

...但我不希望这种行为 - 我希望Textbox元素的宽度与网格列的宽度相关联,而不是依赖于内容.

现在,我已经看过各种各样的SO问题了,这个问题最接近我所追求的: 如何自动缩放一组控件的字体大小?

...但它仍然没有真正处理文本框宽度行为(当它与Viewbox beahvior交互时),这似乎是主要问题.

我尝试过各种各样的东西 - 不同的Horizo​​ntalAlignment ="拉伸"设置等等,但到目前为止还没有任何工作.这是我的XAML:

<Window x:Class="WpfApp1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp1"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="1*" />
            <ColumnDefinition Width="5" />
            <ColumnDefinition Width="2*" />
        </Grid.ColumnDefinitions>

        <StackPanel Grid.Column="0">
            <StackPanel.Background>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="Silver" Offset="0"/>
                    <GradientStop Color="White" Offset="1"/>
                </LinearGradientBrush>
            </StackPanel.Background>

            <Viewbox Stretch="Uniform" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                <Grid Background="White">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="1*" />
                        <ColumnDefinition Width="2*" />
                        <ColumnDefinition Width="1*" />
                        <ColumnDefinition Width="2*" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" …
Run Code Online (Sandbox Code Playgroud)

c# wpf grid textbox viewbox

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

C#如何获取正在设置的属性的名称

我有一个数据库对象类,做了一堆繁重的工作.然后,我扩展该对象并构建表示要修改的实际对象和字段的类.它基本上看起来像这样:

public class MyObject : DatabaseObject
{
    public string FieldX
    {
        get { return GetValue<string>("FieldX"); }
        set { SetValue<string>("FieldX", value); }
    }

    public int FieldY
    {
        get { return GetValue<int>("FieldY"); }
        set { SetValue<int>("FieldY", value); }
    }
}

public class DatabaseObject
{
    public T GetValue<T>(string FieldName)
    {
         // Code that actually gets the right value
    }

    public void SetValue<T>(string FieldName, T value)
    {
         // Code that actually sets the value in the right place
    }
}
Run Code Online (Sandbox Code Playgroud)

这样,我以后可以实例化MyObject并开始通过代码设置属性.我们的想法是生成更简单,更易于维护的代码.

它在实践中很有效.但是,我注意到MyObject的代码非常重复.例如,使用FieldX,我最终在get/set中指定了"string"类型,并且还必须在get/set中指定属性名称"FieldX".

我想知道是否有办法进一步简化代码以减少重复.

我知道我可以使用反射: …

c# reflection types properties

6
推荐指数
2
解决办法
852
查看次数

C - 对大型2D整数数组进行排序的最快方法

我有一个2D数组,其中每行包含6个已按升序排序的整数.例:

1  2  3  4  5  6
6  8  9 10 13 15
1  4  5  6  7  9
1  4  5  6  7  8
3 18 19 20 25 34
Run Code Online (Sandbox Code Playgroud)

预期产量:

1  2  3  4  5  6
1  4  5  6  7  8
1  4  5  6  7  9
3 18 19 20 25 34
6  8  9 10 13 15
Run Code Online (Sandbox Code Playgroud)

实际数据包含8米到33米这样的记录.我正在尝试确定排序此数组的最快方法.我目前有一些使用qsort的工作代码:

qsort电话:

qsort(allRecords, lineCount, sizeof(int*), cmpfunc);
Run Code Online (Sandbox Code Playgroud)

cmpfunc:

int cmpfunc (const void * a, const void * b)
{ …
Run Code Online (Sandbox Code Playgroud)

c arrays sorting performance

6
推荐指数
2
解决办法
248
查看次数

Curl 无法验证 Verisign 颁发的通配符 SSL 证书

我有一个需要使用 cURL 安全连接到网站 foo.bar.com 的脚本,该网站由 *.bar.com 的通配符 SSL 证书覆盖。

通配符证书由威瑞信颁发,所有浏览器都信任它,没有任何问题。但是,我无法连接 PHP / cURL(至少在不禁用证书验证的情况下不能)。

只是为了隔离问题,我尝试仅使用命令行 cURL(7.21.1 版)进行连接。我从 Mozilla 下载了一个更新的 CA 包(保存为 cacert.pem),然后运行:

curl --cacert /path/to/cacert.pem "https://foo.bar.com"
Run Code Online (Sandbox Code Playgroud)

结果是:

curl: (60) SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
More details here: http://curl.haxx.se/docs/sslcerts.html

curl performs SSL certificate verification by default, using a "bundle"
 of Certificate Authority (CA) public keys (CA certs). If the default
 bundle file isn't adequate, you can specify an alternate file
 using the …
Run Code Online (Sandbox Code Playgroud)

php ssl https curl

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

标签 统计

c# ×2

arrays ×1

c ×1

curl ×1

grid ×1

https ×1

performance ×1

php ×1

properties ×1

reflection ×1

sorting ×1

ssl ×1

textbox ×1

types ×1

viewbox ×1

wpf ×1