Difference between x:Reference and x:Name
{x:Reference ...}
-> returns just a reference of an object it doesn't create that "bridge" between two properties like binding would do. Behind all that a service is being used that searches for the given name in a specific scope which is usually the window itself.
{Binding ElementName="..." }
-> first of all it creates that binding object then it searches for the object name but not by using the same technique under the hood as x:Reference. The search algorithm moves up and/or down in VisualTree to find the desired element. Therefore a functional VisualTree is always needed. As example when used inside a Non-UiElement, it won't work. In the end the Binding stays and does its daily bread.
This won't work:
<StackPanel>
<Button x:name="bttn1" Visibility="Hidden">Click me</Button>
<DataGrid>
<DataGrid.Columns>
<DataGridTextColumn Visibility="{Binding ElementName=bttn1, Path=DataContext.Visibility}"/>
....
This works:
<StackPanel>
<Button x:name="bttn1" Visibility="Hidden">Click me</Button>
<DataGrid>
<DataGrid.Columns>
<DataGridTextColumn Visibility="{Binding Source={x:Reference bttn1} Path=DataContext.Visibility}"/>
....
Sort of like that :)
最新文章
- 【Python】range和xrange区别
- HTTP协议 (四) 缓存
- python 中接口的实现
- iOS : 静态库制作
- 利用Meida Service的Java SDK来调用Azure Media Services的Index V2实现视频字幕自动识别
- jquery如何实现domReady和onload判断的
- [转载]Jquery Form插件表单参数
- [LeetCode OJ] Decode Ways
- your local changes would be overwritten by merge. commit stash or revert them to proceed. view them
- udacity/CarND-Path-Planning-Project 工程详细配置过程——吐血整理
- IT男的别样人生,爱折腾,竟然辞职跑丽江去了
- RF自动化测试
- SQL审计 Yearning 介绍(SQL审核平台)
- Linux下创建和删除软、硬链接 可临时处理空间不足
- Window 任务栏清除历史记录
- 初探nginx负载均衡配置
- sqoop快速入门
- 如何自定义Tomcat Realm实现我们的用户认证需求
- PAT甲题题解-1042. Shuffling Machine (20)-模拟
- Java:多线程,CountDownLatch同步器