Trying to make a UserControl that may contain another control. Below is the corresponding code.
<UserControl … … … … > <Grid DataContext="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}}"> … … … <ContentPresenter Content="{Binding SomeContent}"/> … … … </Grid> </UserControl>
And using this UserControl as shown below -
<myCtrl:ContainerUserControl FontSize="18pt"> <myCtrl:ContainerUserControl.SomeContent> <Grid> <TextBox Text="Hello World"/> </Grid> </myCtrl:ContainerUserControl.SomeContent> </myCtrl:ContainerUserControl >
The problem is that FontSize is not inherited in the TextBox. I can install FontSize in a TextBox, but this is not an elegant solution. I tried using ContentControl but no change. Also tried using
<ContentPresenter TextElement.FontSize="{Binding FontSize}" Content="{Binding SomeContent}"/>
Does not work. FontSize is not the only thing that bothers me. I may need another property to inherit.
What can be done to solve this problem?
wpf xaml
Amit Hasan Nov 11 '15 at 19:29 2015-11-11 19:29
source share