小编ime*_*kon的帖子

如何获取TextBox以填充可调整大小的列?

我正在尝试使用TextBox来填充可调整大小的列中的可用空间.TextBox是用户控件的一部分:

<UserControl x:Class="TextBoxLayout.FieldControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Label Grid.Column="0">Name</Label>
        <TextBox Grid.Column="1"/>
    </Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud)

此用户控件位于带垂直拆分器的窗口中:

<Window x:Class="TextBoxLayout.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:TextBoxLayout"
    Title="Text box layout" Height="400" Width="600">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition MinWidth="100"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition MinWidth="100"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition/>
        </Grid.RowDefinitions>

        <local:FieldControl Grid.Column="0" Grid.Row="0" MaxWidth="200" HorizontalAlignment="Left"/>

        <TextBlock Grid.Column="0" Grid.Row="1" Text="Testing"/>

        <GridSplitter Grid.Column="1" Grid.Row="0" Grid.RowSpan="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="3"/>

        <TextBlock Grid.Column="2" Grid.Row="0" Grid.RowSpan="2" Text="Testing"/>
    </Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)

问题是TexTBox似乎非常狭窄 - 我想要它做的是填充左列并使用拆分器调整大小.我怎么做?

wpf textbox splitter stretch

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

如何在类型常量中包含方法指针?

我想在记录中使用对象的过程,如下所示:

TCommandRec = record
  name: string;
  fn: procedure of object;
end;
Run Code Online (Sandbox Code Playgroud)

我可以通过赋值创建一个数组:

commands: array [0..1] of TCommandRec;

...

commands[0].name := '-help';
commands[0].fn := DoHelp;
commands[1].name := '-load';
commands[1].fn := DoLoad;
Run Code Online (Sandbox Code Playgroud)

我真正想做的是声明一个常量:

const
  cmds: array [0..1] of TCommandRec =
  (
    (name: '-help'; fn: DoHelp),
    (name: '-load'; fn: DoLoad)
  );
Run Code Online (Sandbox Code Playgroud)

但是,我收到了DoHelp和DoLoad的错误 - 期望的常量表达式.这是一类的两种方法.是否有一些语法我需要用来使这项工作或我在运行时坚持构建数组?

delphi

8
推荐指数
1
解决办法
295
查看次数

为什么等待永远不会回来?

我看到等待似乎永远不会回来.这是示例代码:

public partial class MainWindow : Window, INotifyPropertyChanged
{
    private string _status;
    private CancellationTokenSource _cancellationTokenSource;

    public MainWindow()
    {
        InitializeComponent();

        _status = "Ready";

        DataContext = this;
    }

    public string Status
    {
        get { return _status; }
        set
        {
            _status = value;
            OnPropertyChanged(nameof(Status));
        }
    }

    private void OnStart(object sender, RoutedEventArgs e)
    {
        Status = "Running...";

        _cancellationTokenSource = new CancellationTokenSource();

        StartProcessing();
    }

    private void OnStop(object sender, RoutedEventArgs e)
    {
        _cancellationTokenSource.Cancel();
    }

    private async void StartProcessing()
    {
        try
        {
            await new Task(() =>
            { …
Run Code Online (Sandbox Code Playgroud)

c# task-parallel-library async-await

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

找不到WPF资源

如果我在XAML中使用以下内容,则会收到错误消息:

    <Style TargetType="TreeViewItem">
        <Style.Triggers>
            <DataTrigger Binding="{Binding Selected}" Value="True">
                <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightColor}}"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>
Run Code Online (Sandbox Code Playgroud)

错误是:

System.Windows.ResourceDictionary Warning: 9 : Resource not found; ResourceKey='#FF316AC5'
Run Code Online (Sandbox Code Playgroud)

wpf systemcolors

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

C++中的新功能语法

我是一名程序员,在进行更改并学会避免STL时学习了C++.相反,我使用了MFC容器类和我可能使用的框架可用的任何容器类.

我也从未真正使用智能指针.8)

所以,我正在研究C++中的新功能(使用VS 2013)

以下编译和工作正常:

vector<string> names;
names.push_back("tom");
names.push_back("dick");
names.push_back("harry");
names.push_back("bob");
names.push_back("percy");
names.push_back("freddie");
names.push_back("sam");

for (auto name : names)
{
    cout << "Name: " << name << endl;
}
Run Code Online (Sandbox Code Playgroud)

以下不是:

vector<unique_ptr<Thing>> things;
things.push_back(unique_ptr<Thing>(new Thing("tom", 23)));
things.push_back(unique_ptr<Thing>(new Thing("dick", 26)));
things.push_back(unique_ptr<Thing>(new Thing("harry", 33)));
things.push_back(unique_ptr<Thing>(new Thing("fred", 43)));
things.push_back(unique_ptr<Thing>(new Thing("bob", 53)));

for (auto thing : things)
{

}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误消息:

1>c:\dev\src\samples\consoletest\consoletest\vectorstuff.cpp(34): error C2280: 'std::unique_ptr<Thing,std::default_delete<_Ty>>::unique_ptr(const std::unique_ptr<_Ty,std::default_delete<_Ty>> &)' : attempting to reference a deleted function
1>          with
1>          [
1>              _Ty=Thing
1>          ]
1>          c:\program files (x86)\microsoft …
Run Code Online (Sandbox Code Playgroud)

c++

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

Delphi Flicker Free,带有外观

如果我使用绘图框和滚动条创建一个简单的应用程序,在绘图框中绘制一些矩形,并使滚动条更改刷新绘制框,当我拖动滚动条时我得到一个无闪烁的显示(DoubleBuffer设置为表格):

procedure TMainForm.OnHorzChange(Sender: TObject);
begin
    PaintBox.Refresh;
end;

procedure TMainForm.OnPaint(Sender: TObject);
var
    x, y: integer;

begin
    with PaintBox.Canvas do
    begin
        Pen.Color := clBlack;
        Brush.Color := clGray;
        for y := 0 to 9 do
            for x := 0 to 9 do
                Rectangle(x * 32, y * 32, x * 32 + 24, y * 32 + 24);
    end;
end;
Run Code Online (Sandbox Code Playgroud)

如果我然后将外观更改为Carbon,则闪烁返回:

program test;

uses
    Vcl.Forms,
    main in 'main.pas' {MainForm},
    Vcl.Themes,
    Vcl.Styles;

{$R *.res}

begin
    Application.Initialize;
    Application.MainFormOnTaskbar := True;
    TStyleManager.TrySetStyle('Carbon');
    Application.CreateForm(TMainForm, MainForm);
    Application.Run;
end. …
Run Code Online (Sandbox Code Playgroud)

delphi vcl-styles

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

如何在同一个线程上使用相同的互斥锁锁定两次?

我有这个课(简化):

// thing.h

#include <mutex>

class Thing
{
public:
    void process();
    void inner();

private:
    std::mutex lock;
};

// thing.cpp

#include "Thing.h"

using namespace std;

void Thing::process()
{
    lock_guard<mutex> locking(lock);

    inner();
}

void Thing::inner()
{
    lock_guard<mutex> locking(lock);
}
Run Code Online (Sandbox Code Playgroud)

如果我打电话来处理,我得到一个例外:

Microsoft C++ exception: std::system_error at memory location 0x006FF16C.
Run Code Online (Sandbox Code Playgroud)

锁定同一线程中的同一个锁会导致此异常.除了例外,我怎么能这样做?我想添加一个标志:

volatile bool alreadyLocked;
Run Code Online (Sandbox Code Playgroud)

改变内在:

void Thing::inner()
{
     if (!alreadyLocked)
     {
         lock_guard<mutex> locking(lock);
         alreadyLocked = true;
         ...something magic happens here...
         alreadyLocked = false;
     }
}
Run Code Online (Sandbox Code Playgroud)

然而,这感觉很脆弱......有没有正确的方法来做到这一点?

c++ mutex

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

如何在FMX画布上的Delphi中画一条线

这是与Delphi Berlin 10.1 Update 2一起使用的

以下作品(画线):

brush := TStrokeBrush.Create(TBrushKind.Solid, TAlphaColors.Lightgray);
brush.Thickness := 2;
with Canvas do
begin
    BeginUpdate;
    DrawLine(PointF(10, 10), PointF(100, 10), 1, brush);
    EndUpdate;
end;
Run Code Online (Sandbox Code Playgroud)

以下内容不起作用:

with Canvas do
begin
    BeginUpdate;
    Stroke.Color := TAlphaColors.Black;
    Stroke.Thickness := 2.0;
    DrawLine(PointF(10, 10), PointF(100, 10), 1);
    EndUpdate;
end;
Run Code Online (Sandbox Code Playgroud)

为什么我不能使用第二个?如何使它工作,还是应该像第一个示例一样坚持创建描边画笔?

我提供了一个最小的应用程序:

主目录

unit main;

interface

uses
    System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Objects;

type
    TMainForm = class(TForm)
        PaintBox: TPaintBox;
        procedure OnPaint(Sender: TObject; Canvas: TCanvas);
    private
        { Private declarations }
    public …
Run Code Online (Sandbox Code Playgroud)

delphi canvas paintbox firemonkey delphi-10.1-berlin

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