亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

WPF數據綁定:如何訪問“父”數據上下文?

WPF數據綁定:如何訪問“父”數據上下文?

WPF數據綁定:如何訪問“父”數據上下文?我有一個窗口中包含的列表(見下文)。窗口DataContext有兩個屬性,Items和AllowItemCommand。如何獲取針對窗口的屬性需要解析Hyperlink的Command屬性DataContext?<ListView ItemsSource="{Binding Items}">   <ListView.View>     <GridView>       <GridViewColumn Header="Action">         <GridViewColumn.CellTemplate>           <DataTemplate>             <StackPanel>               <TextBlock>                 <!-- this binding is not working -->                 <Hyperlink Command="{Binding AllowItemCommand}"                            CommandParameter="{Binding .}">                     <TextBlock Text="Allow" />                 </Hyperlink>               </TextBlock>             </StackPanel>           </DataTemplate>         </GridViewColumn.CellTemplate>       </GridViewColumn>     </GridView>   </ListView.View></ListView>
查看完整描述

3 回答

?
BIG陽

TA貢獻1859條經驗 獲得超6個贊

你可以嘗試這樣的事情:

...Binding="{Binding RelativeSource={RelativeSource FindAncestor, 
AncestorType={x:Type Window}}, Path=DataContext.AllowItemCommand}" ...


查看完整回答
反對 回復 2019-08-06
?
慕村225694

TA貢獻1880條經驗 獲得超4個贊

這也有效:

<Hyperlink Command="{Binding RelativeSource={RelativeSource AncestorType=ItemsControl},
                             Path=DataContext.AllowItemCommand}" />

ListView將繼承其DataContextWindow,所以它的使用在這一點上,太。
并且,因為ListView,就像類似的控件(例如Gridview,ListBox等等)是其子類ItemsControlBinding對于這樣的控件將完美地工作。


查看完整回答
反對 回復 2019-08-06
?
臨摹微笑

TA貢獻1982條經驗 獲得超2個贊

這也適用于Silverlight 5(也許更早,但我還沒有測試過)。我使用了這樣的相對來源,它工作得很好。

RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=telerik:RadGridView}"


查看完整回答
反對 回復 2019-08-06
  • 3 回答
  • 0 關注
  • 1403 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號