2017-04-06 76 views
-1
設置在ContentControl中的孩子

我背後有響應的一些事情我已經設置了編輯器歡迎使用屬性爲爲什麼不是我的風格得到WPF

WPF

<ContentControl> 
     <ContentControl.Resources> 
      <Style TargetType="selections:EntitySelector"> 
       <Setter 
        Property="EntitySelectorManager" 
        Value="{Binding SelectorManager, Mode=OneWay }"/> 
      </Style> 
     </ContentControl.Resources> 
     <ContentControl.Content> 
      <Binding Path="Editor" /> 
     </ContentControl.Content> 
    </ContentControl> 

然後在代碼下面的XAML代碼

this.Editor = element 

其中元素是包含一個或多個對象的控件EntitySelector對象。然而,一旦控制在視覺樹中實例化,我可以看到綁定沒有起作用。

首先,我檢查了的DataContextSelectorManager財產在ContentControl中的水平。這似乎是爲了

enter image description here

現在我進入ContentControl中,看看是否有任何EntitySelector控制有自己的EntitySelectorManager屬性進行設置。

enter image description here

你可以看到有一個綁定表達式,但結果是零。爲什麼是這樣?

回答

0

我有一個解決方案,但我不太喜歡它。使用從代碼隱藏

public WeinCamWindow(WeinCamWorkPiece camViewModel) 
{ 
    ViewModel = camViewModel; 
    InitializeComponent(); 
    DataContext = ViewModel; 
    this.Resources["EntitySelectionManager"] = ViewModel.SelectorManager; 

} 

,並在風格初始化的動態資源使用動態資源

<Style TargetType="selections:EntitySelector"> 
    <!-- 'EntitySelectionManager' is set in code behind. --> 
    <Setter Property="EntitySelectorManager" 
      Value="{DynamicResource EntitySelectionManager}" /> 
</Style> 

的dyamic資源propogates在所有其他招數我試過沒有工作。

相關問題