为什么不是我的风格得到WPF
问题描述:
设置在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对象。然而,一旦控制在视觉树中实例化,我可以看到绑定没有起作用。
首先,我检查了的DataContext的SelectorManager财产在ContentControl中的水平。这似乎是为了
现在我进入ContentControl中,看看是否有任何EntitySelector控制有自己的EntitySelectorManager属性进行设置。
你可以看到有一个绑定表达式,但结果是零。为什么是这样?
答
我有一个解决方案,但我不太喜欢它。使用从代码隐藏
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在所有其他招数我试过没有工作。