小编Noa*_*m M的帖子

WPF更改组合框的背景颜色

在我的WPF应用程序中,我只想更改组合框的背景颜色.我不是指下拉,我想要的只是选择背景设置的任何项目.就像设置按钮的背景一样 - 当控件显示在屏幕上时,它应该具有LightYellow背景.而已.我在网上搜索了很多,但到处都可以找到下拉背景颜色的解决方案.我尝试将SolidColorBrush和Style.Triggers应用到Combobox的TextBlock,但没有成功.通过添加SolidColorBrush线,我得到了我的下拉背景设置,但这不是我想要的.我的代码是:

<ComboBox ItemsSource="{Binding MtrCm}" SelectedValue="{Binding WellboreDiameter_Unit, Mode=TwoWay}" Grid.Row="1" Height="23" HorizontalAlignment="Right" Margin="0,26,249,0" x:Name="cboWellDiameter" VerticalAlignment="Top" Width="120"   Background="LightYellow"  >
    <ComboBox.Resources>
        <SolidColorBrush x:Key="{x:Static SystemColors.WindowBrushKey}" Color="Yellow" />
        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Yellow" />
        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Yellow" />
        <Style TargetType="TextBlock">
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorType=ComboBoxItem}}" Value="True">
                    <Setter Property="Background" Value="Red" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </ComboBox.Resources>
</ComboBox>
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮助我设置他正在寻找的所需组件的背景.

谢谢

c# wpf combobox background-color

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

获取wpf WriteableBitmap的DrawingContext

有没有办法获得一个DrawingContext(或类似的)WriteableBitmap?也就是说允许你调用简单的DrawLine/ DrawRectangle/ etc类方法,而不是直接操作原始像素.

wpf drawing bitmap

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

将QProcess输出读取为字符串

我有一个像这样使用QProcess的代码.

int main(int argc, char *argv[])
{
    int status=0;
    QProcess pingProcess;
    QString ba;
    QString exec = "snmpget";
    QStringList params;
     params << "-v" << "2c" << "-c" << "public" << "10.18.32.52" <<    ".1.3.6.1.4.1.30966.1.2.1.1.1.5.10";
    status=pingProcess.execute(exec, params);
    pingProcess.close();
}
Run Code Online (Sandbox Code Playgroud)

这输出以下内容.

SNMPv2-SMI::enterprises.30966.1.2.1.1.1.5.10 = STRING: "0.1"
Run Code Online (Sandbox Code Playgroud)

我想把这个输出作为字符串.我搜索了这个,我找不到解决方案.提前致谢.

c++ qstring qt stdout qprocess

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

Caliburn Micro Guard方法不评估财产变化

我一直在使用Caliburn Micro MVVM框架,并且在防护方法方面遇到了一些问题.

我有一个视图模型:

public class MyViewModel : PropertyChangedBase, IMyViewModel
Run Code Online (Sandbox Code Playgroud)

财产:

public DateTime? Date
{
   get{return this.date; }
   set
   {
      this.date = value;
      this.NotifyOfPropertyChange(() => Date);
   }
}
Run Code Online (Sandbox Code Playgroud)

另外,我的视图模型中有一个方法,带有一个保护方法

public void Calculate()
{
    // ..some code..
}

public bool CanCalculate()
{
    return this.Date.HasValue;
}
Run Code Online (Sandbox Code Playgroud)

我的视图中有一个按钮:

我遇到的问题是CanCalculate方法在加载时执行,但是当我在文本字段中输入值时,它不会重新评估CanCalculate方法.我在设置数据绑定视图模型属性时触发属性更改事件,那么可能是什么问题?

c# wpf mvvm caliburn.micro

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

如何在XAML中"创建"的Code Behind中访问控件

我在XAML中创建了一个控件,我希望通过Code Behind访问它.

<wincontrols:LiveTileFrameElement Name="PendingAuthsFrame1" Text="Pending" />

this.PendingAuthsFrame1.Text = "334";
Run Code Online (Sandbox Code Playgroud)

但是,我在上面的第二个语句中得到了一个构建错误,说明MyApp.MainWindow does not contain a definition for 'PendingAuthsFrame1' and no extension method.... 它一直在继续,但你得到了我猜的想法.

我错过了什么或做错了什么?

.net c# wpf xaml

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

不调用OnDetaching函数的行为

我有WPF behavior特定的控制权.当我关闭保持控件的窗口时,OnDetaching不会调用该函数.

行为继续存在(因为它注册的事件),虽然窗口不再存在(内存泄漏).

为什么OnDetaching功能没有解雇****,我该如何解决?

protected override void OnAttached()
{
     base.OnAttached();

     this.AssociatedObject.MouseLeftButtonDown += AssociatedObject_PlotAreaMouseLeftButtonDown;
     this.AssociatedObject.MouseLeftButtonUp += AssociatedObject_PlotAreaMouseLeftButtonUp;
     this.AssociatedObject.MouseMove += AssociatedObject_PlotAreaMouseMove;
}

protected override void OnDetaching()
{
     base.OnDetaching();

     this.AssociatedObject.MouseLeftButtonDown -= AssociatedObject_PlotAreaMouseLeftButtonDown;
     this.AssociatedObject.MouseLeftButtonUp -= AssociatedObject_PlotAreaMouseLeftButtonUp;
     this.AssociatedObject.MouseMove -= AssociatedObject_PlotAreaMouseMove;
}
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml memory-leaks mvvm

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

解析Qt中的csv文件

是否有人熟悉如何解析csv文件并将其放入字符串列表中.现在我正在整个csv文件并放入字符串列表.我想弄清楚是否有办法只获得第一列.

#include "searchwindow.h"
#include <QtGui/QApplication>

#include <QApplication>
#include <QStringList>
#include <QLineEdit>
#include <QCompleter>
#include <QHBoxLayout>
#include <QWidget>
#include <QLabel>

#include <qfile.h>
#include <QTextStream>


int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QWidget *widget = new QWidget();
    QHBoxLayout *layout = new QHBoxLayout();

    QStringList wordList;

    QFile f("FlightParam.csv");
    if (f.open(QIODevice::ReadOnly))
    {
        //file opened successfully
        QString data;
        data = f.readAll();
        wordList = data.split(',');

        f.close();
    }

    QLabel *label = new QLabel("Select");
    QLineEdit *lineEdit = new QLineEdit;
    label->setBuddy(lineEdit);

    QCompleter *completer = new QCompleter(wordList);
    completer->setCaseSensitivity(Qt::CaseInsensitive); //Make …
Run Code Online (Sandbox Code Playgroud)

c++ csv qt qfile qt5

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

在WPF控件上显示"加载"指示符的最佳方法是什么

在C#.Net WPF期间UserControl.Load - >

在UserControl上显示旋转圆圈/"加载"指示器的最佳方法是什么,直到它完成收集数据并呈现其内容为止?

.net c# wpf user-controls

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

在WPF中使用计时器刷新UI(使用BackgroundWorker?)

我们在WPF中有一个应用程序,它通过ObservableCollection显示数据.5分钟后,我想刷新数据.

我以为我可以将System.Timers.Timer对象用于其Elapsed事件,然后调用a BackgroundWorker来调用启动作业的方法.该方法位于ViewModel类上.

但似乎线程存在问题.

所以我尝试了Dispatcher,但同样的事情.

这是我的(简化和未优化)代码:

/// <summary>
/// Initializes a new instance of the <see cref="ApplicationController"/> class.
/// </summary>
public ApplicationController()
{
    CreateDefaultTabs();

    Timer timer = new Timer(20000); //20 secs for testing purpose.
    timer.AutoReset = true;
    timer.Enabled = true;
    timer.Elapsed += new ElapsedEventHandler(OnTimeBeforeRefreshElapsed);
    timer.Start();
}

private void OnTimeBeforeRefreshElapsed(object sender, ElapsedEventArgs e)
{
    Dispatcher.CurrentDispatcher.Invoke(new Action(() => { RefreshData(); }));
    Dispatcher.CurrentDispatcher.Invoke(new Action(() => { UpdateLayout(); }));
}

private void RefreshData()
{
    foreach (object tab in _tabItems) …
Run Code Online (Sandbox Code Playgroud)

c# wpf timer backgroundworker

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

打印WPF的对话框和打印预览对话框

是否有WPF的打印对话框,在WPF中打印预览对话框,如Google Chrome或Word?

就像Google Chrome一样.

此时我使用Windows窗体中的打印预览对话框.我也尝试使用它的WPF版本.但WPF没有PrintPreviewDialogPrintPrewiewControl.这是我的代码:

//To the top of my class file:
using Forms = System.Windows.Forms;

//in a methode on the same class:
PageSettings setting = new PageSettings();
setting.Landscape = true;

_document = new PrintDocument();
_document.PrintPage += _document_PrintPage;
_document.DefaultPageSettings = setting ;

Forms.PrintPreviewDialog printDlg = new Forms.PrintPreviewDialog();
printDlg.Document = _document;
printDlg.Height = 500;
printDlg.Width = 200;

try
{
    if (printDlg.ShowDialog() == Forms.DialogResult.OK)
    {
        _document.Print();
    }
}
catch (InvalidPrinterException)
{
    MessageBox.Show("No printers found.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
Run Code Online (Sandbox Code Playgroud)

我也搜索了一个NuGet包,但没有发现真的很好.

c# printing wpf xaml print-preview

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