2013-04-29 38 views
0

我想設置使用多重綁定的按鈕的IsEnabled屬性,因爲此屬性取決於三個變量。爲什麼我不能在按鈕的IsEnabled屬性中使用多重綁定?

如果我將設置內容屬性格式,我可以使用此代碼:

<Button Height="23" HorizontalAlignment="Left" Margin="629,49,0,0" Name="btnMyButton" VerticalAlignment="Top" Width="75"> 
        <Button.Content> 
         <MultiBinding Converter="{StaticResource myMultiValueConverter}"> 
          <Binding ElementName="MyElement"/> 
          <Binding /> 
         </MultiBinding> 
        </Button.Content> 
</Button> 

我嘗試使用此代碼:

<Button Height="23" HorizontalAlignment="Left" Margin="629,49,0,0" Name="btnMyButton" VerticalAlignment="Top" Width="75"> 
        <Button.IsEnabled> 
         <????? 

但在這種情況下,雖然Button.IsEnabled是可用,在下一行我找不到Multibinding關鍵字,所以我不能使用IsEnabled屬性的多重綁定。

爲什麼?有沒有辦法用多值轉換器設置IsEnabled屬性?

謝謝。

回答

2

語法應與您的Button.Content完全相同 - 只需將"Content"替換爲"IsEnabled"即可。

<Button.IsEnabled> 
    <MultiBinding Converter="{StaticResource myMultiValueConverter}"> 
     <Binding ... /> 
     <Binding ... /> 
     <Binding ... /> 
    </MultiBinding> 
</Button.IsEnabled> 

它可能無法自動完成你因爲IsEnabled屬性需要一個布爾值,而不是一個MultiBinding對象,但它不應該給你任何錯誤,將編譯和執行就好了。

(它自動完成了Button.Content因爲Content屬性爲object類型,其中包括一個MultiBinding對象)

+0

最後我編譯Button.Content,然後通過的IsEnabled更改內容,編譯,然後工作。謝謝。 – 2013-04-29 18:06:27

+0

@Rachel這裏唯一的問題是'UpdateSourceTrigger =「PropertyChanged」'不會觸發綁定。我試着在每個'Binding'元素和'MultiBinding'元素中放入'UpdateSourceTrigger =「PropertyChanged」',但它不更新。我必須改變它的工作重點 – Ozkan 2017-09-01 12:26:40

相關問題