我在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)
问候,
我在项目中使用该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
我没有实现的问题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)
这会让我感兴趣:
感谢您的提示!
当我移动一个"主"窗口时,我想移动两个或更多粘性窗口
我想做这样的事情
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) 我有一个TComboBox与Style:= 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:= clBlack的WndProc或别的什么也没有发生.
谷歌搜索给了我一些关于改变一个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) 有点像这样的东西.
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)
但是,我知道这种语法是错误的,我正在寻找一些建议!几乎可以通过代码选择项目(就像你点击它一样).根据它的名字.
如何让 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 ×6
c# ×4
binding ×2
.net ×1
.net-4.0 ×1
async-await ×1
asynchronous ×1
combobox ×1
controls ×1
datagrid ×1
delphi ×1
delphi-xe2 ×1
fonts ×1
infragistics ×1
local ×1
msdn ×1
properties ×1
selecteditem ×1
sticky ×1
windows ×1
wpfdatagrid ×1