2013-06-06 82 views
0
<Window.Resources> 
    <ResourceDictionary>    
     <Style TargetType="{x:Type propgrid:PropertyGridDataAccessorItem}"> 
      <Style.Triggers> 
       <Trigger Property="DataAccessorType" Value="Category"> 
        <Setter Property="IsExpanded" Value="{Binding DisplayName, RelativeSource={x:Static RelativeSource.Self}, ConverterParameter=???, Converter={local:ExpandedCategoryConverter}}"/> 
       </Trigger> 
      </Style.Triggers> 
     </Style> 
    </ResourceDictionary> 
</Window.Resources> 

問題是我不知道如何從我的ViewModel作爲ConverterParameter發送一個屬性。我想有一些像ConverterParameter =「{Binding MyValue}」,但它是不可能的。我試過這樣的Multibinding:設置ConverterParameter風格

<Trigger Property="DataAccessorType" Value="Category"> 
    <Setter Property="IsExpanded"> 
     <Setter.Value> 
      <MultiBinding Converter="{local:ExpandedCategoryConverter}"> 
       <Binding Path="DisplayName"/> 
       <Binding Path="MyProperty"/> 
      </MultiBinding> 
     </Setter.Value> 
    </Setter> 
</Trigger> 

但我的屬性總是爲空。

任何人知道如何處理這個問題呢?

日Thnx提前

+0

是否有在VS輸出窗口任何約束力的錯誤消息?至少在單個綁定中,您正在設置'RelativeSource',但在MultiBinding中不這樣做。 – Clemens

+0

在我的轉換器類在調試模式我得到DisplayName罰款,但ExpandCategory是 - unset({DependencyProperty.UnsetValue})。 任何想法如何解決它? – Sasha

+0

什麼是ExpandCategory?在你的問題中找不到。是否有綁定錯誤信息或不?運行應用程序時,請查看Visual Studio中的輸出窗口。 – Clemens

回答

0

你得到DependencyProperty.UnsetValueMyProperty(或ExpandCategory),因爲結合不產生價值。該IMultiValueConverter.Convert方法的values參數的MSDN文檔說:

,在MultiBinding 源綁定產生的值的數組。值UnsetValue指示源結合具有 沒有值,以提供轉換。

你必須確保<Binding Path="MyProperty"/>作品。我想你沒有正確設置綁定的來源。

+0

日Thnx您的幫助,我發現它有這樣一行:的RelativeSource =「{的RelativeSource模式= FindAncestor,AncestorType =窗口}」 – Sasha