<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      享受代碼,享受人生

      SOA is an integration solution. SOA is message oriented first.
      The Key character of SOA is loosely coupled. SOA is enriched
      by creating composite apps.
        博客園  :: 首頁  :: 新隨筆  :: 聯系 :: 訂閱 訂閱  :: 管理

      How does ElementName Binding work – Part 2 BindingExpression

      Posted on 2010-06-07 20:28  idior  閱讀(2943)  評論(0)    收藏  舉報

      In part 1, I gave a general finding rule for ElementName binding, it works in most cases, however there are some cases you cannot explain them with the general rule. I will cover some of them in the following articles which involve some advanced concept in WPF, like BindingExpression and InheritanceContext.

      What happens when ElementName binding is used in DataTrigger?

      Take a look at following codes:

       

          <Window x:Class="TestElementBindingInUserControl.MainWindow">
              <local:CustomControl1/>
          </Window>

          <Style TargetType="{x:Type local:CustomControl1}">
              <Setter Property="Template">
                  <Setter.Value>
                      <ControlTemplate TargetType="{x:Type local:CustomControl1}">
                          <StackPanel>
                              <Button Name="btn" Content="PFS Button"/>
                              <TextBlock Name="tbk" />
                          </StackPanel>
                          <ControlTemplate.Triggers>
                              <DataTrigger Binding="{Binding ElementName=btn, 
                                                             Path=Content}"                 
                                           Value="PFS Button">
                                  <Setter TargetName="tbk" 
                                          Property="Text" 
                                          Value="PFS TextBlock"/>
                              </DataTrigger>
                          </ControlTemplate.Triggers>
                      </ControlTemplate>
                  </Setter.Value>
              </Setter>
          </Style>
      

       

      Let’s go back to our rules first:

      1. Start from the element which applied the ElementName Binding, keep searching on the logic tree via its logic parent, until an element which has NameScope is found, let’s call it NameScopeElement. If no element owns a NameScope, search will stop.
      2. Call the NameScope.FindName method on the found NameScope.
      3. If the element is found, return it, otherwise try to get the template parent of NameScopeElement; if the template parent is null, it will stop search. or it goes back to step 1, search on the logic tree for element owns a NameScope.

      If we start from DataTrigger, you will find its logic parent would be null, the search will not continue.  Ok, I have to acknowledge the original statement is oversimplified.

      It actually starts form the TargetElement of the BindingExpression which is created by the ElementName Binding. Here it is the CustomControl1.  A little confused here? Let’s see what’s the BindingExpression and what’s the relationship between a BindingExpression and Binding.

      Binding class is the high-level class for the declaration of a binding; the Binding class provides many properties that allow you to specify the characteristics of a binding. A related class,BindingExpression, is the underlying object that maintains the connection between the source and the target. Normally BindingExpression is created by WPF framework, WPF programmer rarely use it in functional codes. A key difference between BindingExpression and Binding is that Binding only contains the Source info while BindingExpression also contains the Target info. That is being said, Binding only tells you where the data comes from, while BindingExpression also defines where the data will transfer to. 

      In most cases, the TargetElement of the BindingExpression will be the DependencyObject whose DependencyProperty is set to a Binding MarkupExtension. For example, the TargetElement of the BindingExpression will be set to the Button object in following codes:

      <Button Content="{Binding ElementName=root,Path=Title}"/>
      

       

      However our style of CustomControl1, DataTrigger is not a DependencyObject and Binding property is not a DependencyProperty either.

      <DataTrigger Binding="{Binding ElementName=btn, Path=Content}"                 
                   Value="PFS Button">

      The BindingExpression will be created in a different way than others, it’s created in StyleHelper.GetDataTriggerValue methods which are internal to the WPF framework. In that method, the BindingExpression’s TargetElement will be set to the object which applies the style that defines the DataTrigger.

      Ok. We are clear of where should we start the search, let’s continue our search. CustomControl1 doesn’t own a NameScope, so we will get his parent which is Window, since Window has a NameScope, we will call the FindName method on Window’s NameScope, but we still cannot find btn. As I said both Window and ControlTemplate have their own NameScope, btn is registered in ControlTemplate’s NameScope rather than Window, so you cannot find btn in Window’s NameScope.

      But if you run the above code, you will see it works. Ok, there is another point i missed in part 1.

      When we start the search from the TargetElement of the BindingExpression, it will check  ResolveNamesInTemplate property of the BindingExpression, if it’s true, it will try to find the element defined in its template first. In our case, the BindingExpression is created from a DataTrigger, the ResolveNamesInTemplate is set to true in StyleHelper.GetDataTriggerValue method, now btn can be found.

      Let’s revised the finding rule:

      1. Get the BindingExpression which is created by the ElementName Binding.
      2. Start from the TargetElement of the BindingExpression. If the value of BindingExpression’s ResolveNamesInTemplate property is true, it will search in the TargetElement’s template, if an element with the same name can be found in its template then return it, else go to next step.
      3. Keep searching on the logic tree via its logic parent, until an element which has NameScope is found, let’s call it NameScopeElement. If no element owns a NameScope, search will stop.
      4. Call the NameScope.FindName method on the found NameScope.
      5. If the element is found, return it, otherwise try to get the template parent of NameScopeElement; if the template parent is null, it will stop search. or it goes back to step 3, search on the logic tree for an element owns a NameScope.
      In part 3, I will give some introduction to InheritanceContext which is also called LogicalParent 2.0. :)
      主站蜘蛛池模板: 亚洲中文字幕无码久久2017| 亚洲最大成人网色| 色偷偷亚洲男人的天堂| 亚洲熟妇丰满多毛xxxx| 日韩av在线一卡二卡三卡 | 成人午夜视频一区二区无码| 无码人妻一区二区三区AV| 色综合色狠狠天天综合网| 中文字幕免费一二三区乱码| 不卡一区二区国产在线| 日本久久久久亚洲中字幕| 国产精品人妻中文字幕| 亚洲精品国产自在久久| 国产亚洲精品久久久久久久软件| 久久精品女人的天堂av| 欧美色欧美亚洲高清在线观看| 老司机午夜精品视频资源| 四虎成人精品无码| 公天天吃我奶躁我的在线观看| 手机无码人妻一区二区三区免费| 免费AV片在线观看网址| 少妇宾馆粉嫩10p| 亚洲成年轻人电影网站WWW| 亚洲中文字幕精品久久| 欧洲一区二区中文字幕| 4399理论片午午伦夜理片| 亚洲av成人午夜福利| 国产精品高清国产三级囯产AV| 精品人妻少妇一区二区三区在线| 国产对白熟女受不了了| 亚洲日韩乱码中文无码蜜桃臀| 九九热在线精品视频观看 | 国产线播放免费人成视频播放| 日韩欧美人妻一区二区三区| 激情久久综合精品久久人妻| 国产亚洲情侣一区二区无| 日日摸夜夜添夜夜添国产三级| 五月天天天综合精品无码| 国内熟妇人妻色在线三级| 青春草公开在线视频日韩| 在线日韩日本国产亚洲|