小编Nit*_*ari的帖子

依赖属性强制绑定问题

我安装了VS2008和VS2010,我看到了一个非常奇怪的行为

在VS2008中,我有一个简单的WPF应用程序:

<TextBox x:Name="textbox" Text="{Binding Path=MyProperty,Mode=TwoWay}"></TextBox>
Run Code Online (Sandbox Code Playgroud)

public Window1()
{
    InitializeComponent();
    DataContext = this;
}
public string MyProperty
{
    get { return (string)GetValue(MyPropertyProperty); }
    set { SetValue(MyPropertyProperty, value); }
}
public static readonly DependencyProperty MyPropertyProperty = DependencyProperty.Register("MyProperty", typeof(string), typeof(Window1), new PropertyMetadata("default",null,Coerce));

private static object Coerce(DependencyObject d, object baseValue)
{
    return "Coerced Value";
}
Run Code Online (Sandbox Code Playgroud)

当我在文本框中输入随机字符串并点击标签时,我希望textbox.Text重置为"Coerced Value".如果我调试我看到应用程序在Coerce功能中断,但UI没有更新.

有趣的是,这个相同的代码在VS2010中工作,UI使用Coerced值进行更新.任何人都有想法发生了什么?

它是WPF错误吗?还是我错过了什么?

c# data-binding xaml coercion

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

如何捕获一个int

我正在使用IL来抛出一个Int32并捕获它.这只是出于好奇,我不想做任何事情,所以请不要告诉我抛出异常而不是int.

.method private hidebysig static void  Main(string[] args) cil managed
{
  .entrypoint
  // Code size       40 (0x28)
  .maxstack  2
  .locals init (object V_0,
       int32 V_1)
  IL_0000:  nop
  .try
  {
    IL_0001:  nop
    IL_0002:  ldsfld     int32 ConsoleApplication3.Program::i
    IL_0007:  throw
  }  // end .try
  catch [mscorlib]System.Object 
  {
    IL_0008:  stloc.0
    IL_0009:  nop
    IL_000a:  ldstr      "In Object catch"
    IL_000f:  call       void [mscorlib]System.Console::WriteLine(string)
    IL_0014:  nop
    IL_0015:  ldloc.0
    IL_0016:  unbox.any  [mscorlib]System.Int32
    IL_001b:  stloc.1
    IL_001c:  ldloc.1
    IL_001d:  call       void [mscorlib]System.Console::WriteLine(int32)
    IL_0022:  nop
    IL_0023:  nop
    IL_0024:  leave.s    IL_0026
  } …
Run Code Online (Sandbox Code Playgroud)

.net il exception-handling

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

如何使用C#中的索引从多图标(.ico)文件访问图标

我想使用ico文件中的第4张图片:C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\VS2008ImageLibrary\1033\VS2008ImageLibrary\VS2008ImageLibrary\Objects\ico_format\WinVista\Hard_Drive.ico

如果我使用Windows Photo Viewer看到此图标,则会显示13个不同的图标.

我已将此ico转储到资源文件中,如何使用索引检索所需的图标.

c# indexing icons

8
推荐指数
2
解决办法
2716
查看次数

C#Directory.Exists ipv6版本

我正在使用Directory.Exists(uncPath)UNC路径,现在如果我使用标准IPv6地址则失败.是否有代码可以处理所有格式的unc - ipv4/ipv6/machiname.

目前我将我的ipv6地址转换为类似的东西2001-0-234-c1ab-0-a0-aabc-3e.ipv6-literal.net并且它可以工作,但是Ipv6本身可以用多种格式表示.我需要能处理所有格式的东西.

c# ipv6

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

WPF:为什么没有消息框在标题栏上有图标

我想要的只是我的消息框应该在其标题栏中显示我的应用程序的图标(或任何其他图标),但它没有,为什么不呢?

wpf icons messagebox

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

WPF 文本框预览事件相关

我有一个 WPF 文本框,并执行以下操作

  1. 输入文本“12345”
  2. 在 3 和 4 之间移动光标(使用箭头或鼠标单击)
  3. 输入 0(因此文本现在为“123045”)

哪个 event/eventargs 可以告诉我在位置 4 处输入了 0。我需要在预览级别知道这一点,以便我可以根据前缀和后缀数字拒绝字符 0。

wpf events textbox preview

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