簡體   English   中英

綁定到模板中的嵌套屬性

[英]Binding to a nested property in template

我想為異步方法創建一個帶加載指示符的按鈕,如下所示:

在此輸入圖像描述

我創建了一個實現ICommandINotifyPropertyChangedAsyncCommand (更多細節見MSDN雜志2014年4月)。

我的AsyncCommand具有Execution屬性,它具有IsNotCompleated屬性。 我想設置Visibility裝載機的財產indincator使用IsNotCompleted財產。

我創建UserControl繼承Button並為此設置樣式。 我嘗試將可見性綁定到Button的Command依賴項屬性。

ControlTemplate的一部分帶有“加載指示器”(我使用內容,而不是可見性,僅作為示例)

 <Label HorizontalAlignment="Center"
        VerticalAlignment="Center"
        Grid.Column="1"
        Content="{Binding Command.Execution.IsNotCompleted}"/>

沒有任何反應。 如果我使用TemplateBinding而不是Binding我將得到編譯錯誤:

  • 不支持嵌套類型:Command.Execution
  • 無法找到類型Command.Execution

這樣做的正確方法是什么?

解決方案是使用RelativeSource.TemplatedParent

<Label HorizontalAlignment="Center"
    VerticalAlignment="Center"
    Grid.Column="1"
    Content="{Binding Command.Execution.IsNotCompleted, RelativeSource={RelativeSource TemplatedParent}}"/>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM