欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 房产 > 家装 > WPF绑定Bind方法合集,实时更新

WPF绑定Bind方法合集,实时更新

2025/2/2 1:38:37 来源:https://blog.csdn.net/weixin_45277117/article/details/143916072  浏览:    关键词:WPF绑定Bind方法合集,实时更新

绑定静态属性x:Static

<TextBlock Text="{x:Static System:Environment.MachineName}" />

绑定到自身的属性RelativeSource Self

<Rectangle Width="100" Height="{Binding Width, RelativeSource={RelativeSource Self}}" />

绑定到集合的当前项:你可以使用Path=Items/来绑定到集合的当前项

public List<string> strings { get; set; } = Enumerable.Repeat("Hello", 10).ToList();
<TextBlock Text="{Binding Path=Items/}" />

表现为第一个Hello,如果是IEnumerable类型则对应yield的顺序

获取集合当前项的第0个成员strings/[0]

public List<string> strings { get; set; } = Enumerable.Repeat("Hello", 10).ToList();
<TextBlock Text="{Binding strings/[0]}" />

获取当前项的第0个元素
表现为第一个Hello的第一个字母,H

特殊绑定(Button.Background).(SolidColorBrush.Color)

(Button.Background).(SolidColorBrush.Color)表示的是Button的Background属性的Color属性。Button.Background是一个Brush类型的属性,SolidColorBrush.Color是SolidColorBrush的一个属性,表示颜色。
由于Background是Brush类型,Brush是抽象类,SolidColorBrush是子类,意为把((SolidColorBrush)(Button.Background)).Color
在这里插入图片描述

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com