views:

16

answers:

0

I need to do this in XAML :

<Grid x:Name="layoutRoot">

    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>

    <SomeUserControl Grid.Row="0" />

    <ui:AdditionalView.UseCase1>
        <ContentControl>
           <TextBlock>aaa</TextBlock>
         </ContentControl>
     </ui:AdditionalView.UseCase1>

</Grid>

First, and most important, I need to have the block in the Something.UseCase1 form. That is how I ended up using attached properties. I defined the AdditionalView class and defined an attached property called UseCase1 on it.

However this does not render the

<TextBlock>aaa</TextBlock> 

at runtime.

How can I achieve this?


Later Edit (1) - I managed to get something to work like so :

<ContentControl Grid.Row="1" Content="{Binding ElementName=layoutRoot, Path=(ui:AdditionalView.UseCase1)}" />

.. but it seems nasty. Any decent way to get this to work?

The AdditionalView class :

public class AdditionalView
{
    public static readonly DependencyProperty UseCase1Property = DependencyProperty.RegisterAttached(
        "UseCase1",
        typeof(object),
        typeof(AdditionalView),
        new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender)
    );

    public static void SetUseCase1(UIElement element, Boolean value)
    {
        element.SetValue(UseCase1Property, value);
    }
    public static object GetUseCase1(UIElement element)
    {
        return element.GetValue(UseCase1Property);
    }
}