小编use*_*aro的帖子

如何在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万
查看次数

如何在UriKind.Relative Path中返回一个文件夹?

我有这个代码:

imgImage.Source = new BitmapImage(new Uri("Images/LivingRoom/chair.png", UriKind.Relative));
Run Code Online (Sandbox Code Playgroud)

这给了我:

{包://应用:,,,/ExpressFurnitureSystem;组件/ UI /图像/客厅/ chair.png}

在这里,我想删除(ui)或去一个文件夹.我的要求是:

{包://应用:,,,/ExpressFurnitureSystem;组件/图像/客厅/ chair.png}

因为我的图像文件夹下的所有图像文件都不在UI/Image下.

感谢您的帮助.

wpf uri path relative-path

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

标签 统计

wpf ×2

binding ×1

local ×1

path ×1

properties ×1

relative-path ×1

uri ×1