小编pun*_*r76的帖子

如何在WPF中绑定控件上的本地属性

我在WPF上有两个控件

<Button HorizontalAlignment="Center"
        Name="btnChange"
        Click="btnChange_Click"
        Content="Click Me" />

<Label Name="lblCompanyId"
       HorizontalAlignment="Center"
       DataContext="{Binding ElementName=_this}"
       Content="{Binding Path=CompanyName}" />
Run Code Online (Sandbox Code Playgroud)

我们可以看到标签绑定到本地属性(在代码Behind中),当我点击按钮时,我在标签上看不到任何值...

下面是我的代码背后......

public static readonly DependencyProperty CompanyNameProperty =
  DependencyProperty.Register("CompanyName", typeof(string), typeof(Window3), new UIPropertyMetadata(string.Empty));

public string CompanyName {
  get { return (string)this.GetValue(CompanyNameProperty); }
  set { this.SetValue(CompanyNameProperty, value); }
}

private void btnChange_Click(object sender, RoutedEventArgs e) {
  this.CompanyName = "This is new company from code beind";
}
Run Code Online (Sandbox Code Playgroud)

问候,

wpf binding properties local

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

如何使用Microsoft.Bcl.Async吧?

我在项目中使用该Microsoft.Bcl.Async ,该项目由另一个不使用异步功能的项目引用.

现在,当我编译解决方案(或仅第二个项目)时,我收到此错误警告:

无法解析主要引用"XYZ.dll",因为它对框架程序集"System.Runtime,Version = 1.5.11.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a"具有间接依赖性,无法在当前目标中解析框架." .NETFramework,版本= V4.0" .要解决此问题,请删除引用"XYZ.dll"或将应用程序重新定位到包含"System.Runtime,Version = 1.5.11.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a"的框架版本.

我在这两个项目中使用这个app.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:bcl="urn:schemas-microsoft-com:bcl">
      <dependentAssembly bcl:name="System.Runtime">
        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.5.16.0" newVersion="2.5.16.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.5.16.0" newVersion="2.5.16.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
Run Code Online (Sandbox Code Playgroud)

我做错了什么?

我不想引用异步包dll.

我不能使用.Net 4.5目标.它必须是.Net 4.

所有项目的目标框架:.NET Framework 4

c# wpf asynchronous .net-4.0 async-await

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

ValueConversion属性的好处是什么?

我没有实现的问题ValueConverter

在MSDN上,我找到了以下ValueConversion属性:

[ValueConversion(typeof(DateTime), typeof(String))]
public class DateConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        DateTime date = (DateTime)value;
        return date.ToShortDateString();
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        string strValue = value as string;
        DateTime resultDateTime;
        if (DateTime.TryParse(strValue, out resultDateTime))
        {
            return resultDateTime;
        }
        return DependencyProperty.UnsetValue;
    }
}
Run Code Online (Sandbox Code Playgroud)

这会让我感兴趣:

  • 什么时候可以使用?
  • 我什么时候应该使用它?

感谢您的提示!

c# wpf msdn binding ivalueconverter

7
推荐指数
0
解决办法
465
查看次数

我该如何移动粘贴/捕捉wpf窗口

当我移动一个"主"窗口时,我想移动两个或更多粘性窗口

我想做这样的事情

private void MainWindow_PreviewMouseMove(object sender, MouseEventArgs e) {
  if (e.LeftButton == MouseButtonState.Pressed) {
    this.DragMove();
    foreach (var window in App.Current.Windows.OfType<Window>()) {
      window.Move(); // move it
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我想用这个解决方案来捕捉窗户

用于WPF的捕捉/粘性/磁性窗口 http://programminghacks.net/2009/10/19/download-snapping-sticky-magnetic-windows-for-wpf/

但我该怎么办呢?

编辑

在Gustavo Cavalcanti的回复之后,我做了一些想法.这是我的问题的粗略解决方案.

using System.Windows;
using System.Windows.Data;

namespace DragMoveForms
{
  /// <summary>
  /// Interaction logic for Window1.xaml
  /// </summary>
  public partial class Window1 : Window
  {
    public Window1() {
      this.InitializeComponent();
    }

    public Window1(Window mainWindow)
      : this() {

      var b = new Binding("Left");
      b.Converter = new MoveLeftValueConverter();
      b.ConverterParameter = …
Run Code Online (Sandbox Code Playgroud)

.net c# windows wpf sticky

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

如何更改已禁用的TComboBox(Delphi)的字体颜色?

我有一个TComboBoxStyle:= csOwnerDrawVariable;我要展示残疾人Font的黑色,而不是在"灰色"的色彩.

这是我从这个来源得到的:

procedure TCustomComboBox.WndProc(var Message: TMessage);
begin
  case Message.Msg of
    CN_CTLCOLORMSGBOX .. CN_CTLCOLORSTATIC, //48434..48440
    WM_CTLCOLORMSGBOX .. WM_CTLCOLORSTATIC:
    begin
      Color:= GetBackgroundColor; // get's the current background state
      Brush.Color:= Color;
    end;
  end;
  inherited;
end;
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

但我希望内部Edit控件的Font颜色为黑色.

如果我改变Font.Color:= clBlackWndProc或别的什么也没有发生.

谷歌搜索给了我一些关于改变一个TEdit只读的tipps ,但这对我没有帮助.

更新

从@Abelisto获得tipp后,现在是我的简短解决方案.

TCustomComboBox = class (TComboBox)
protected
  procedure DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState); override;
end;

procedure TCustomComboBox.DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState);
begin
  if odComboBoxEdit in State …
Run Code Online (Sandbox Code Playgroud)

delphi fonts controls combobox delphi-xe2

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

根据名称以编程方式设置XAM Datagrid的选定项

有点像这样的东西.

private void SearchResult(string nameOfBean)
{
    foreach (Record VARIABLE in mbeanDataGrid.Records)
    {
        if (VARIABLE.ToString().Contains(nameOfBean))
        {
            ((VARIABLE as DataRecord).DataItem as Record).IsSelected = true;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,我知道这种语法是错误的,我正在寻找一些建议!几乎可以通过代码选择项目(就像你点击它一样).根据它的名字.

c# wpf datagrid infragistics selecteditem

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

WPF DataGridTextColumn - 使用“-”而不是“0”

如何让 aDataGridTextColumn显示'-'(连字符)而不是0

以下是数据网格当前的设置方式:

<Grid>
  <DataGrid x:Name="EmployeeHours"
            AutoGenerateColumns="False"
            ItemsSource="{Binding EmployeeHoursLastWeek}"
            Width="Auto">
    <DataGrid.Columns>
      <DataGridTextColumn Header="PerceptionistID"
                          Binding="{Binding PerceptionistID}"
                          Width="100" />
      <DataGridTextColumn Header="Week Of"
                          Binding="{Binding WeekOf, StringFormat={}{0:MM/dd/yyyy}}"
                          Width="75" />
      <DataGridTextColumn Header="Regular Hours"
                          Binding="{Binding WorkHours}"
                          Width="100" />
      <DataGridTextColumn Header="PTO Hours"
                          Binding="{Binding PTOHours}"
                          Width="100" />
      <DataGridTextColumn Header="Holiday Hours"
                          Binding="{Binding HolidayHours}"
                          Width="100" />
    </DataGrid.Columns>
  </DataGrid>
</Grid>
Run Code Online (Sandbox Code Playgroud)

PTOHours 和 HolidayHours 通常为 0,如果任何具有 0 的单元格显示“-”,则可以更轻松地识别具有非 0 值的单元格。

wpf ivalueconverter wpfdatagrid datagridtextcolumn

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