views:

35

answers:

1

I'm not even sure how to express this, so im very sorry if the title is confusing.. My XAML (simplified) looks like this:

<UserControl x:Class="PBA.Application.Client.UserControls.UserControls.FreqReserve.OverView" xmlns:FreqReserve="clr-namespace:PBA.Application.Client.UserControls.UserControls.FreqReserve">
...
    <DockPanel>
        <UserControls:LegendControl>
            <UserControls:LegendControl.Items>
                <UserControls:LegendItem Visibility="{Binding Path=IsDirtyVisible, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type FreqReserve:OverView}}, Converter={StaticResource btvc}}" Identifier="Pink" Text="Ikke sendt"></UserControls:LegendItem>
                <UserControls:LegendItem Identifier="Yellow" Text="Sendt"></UserControls:LegendItem>
                <UserControls:LegendItem Identifier="LightGreen" Text="Accepteret"></UserControls:LegendItem>
                <UserControls:LegendItem Identifier="White" Text="Ikke accepteret"></UserControls:LegendItem>
            </UserControls:LegendControl.Items>
        </UserControls:LegendControl>
    </DockPanel>
</UserControl>

where the LegendItem list is templated inside the legendcontrol.

The binding expression fails with a System.Windows.Data Error: 4. I've tried using elementname instead, with the same results. I'm guessing it has something to do with the LegendItems not actually being directly in the Visual tree but i have no idea (WPF rookie, i know). What am i doing wrong?

+1  A: 

You have a typo in the AncestorType. You want to say FreqReserve.OverView. Also, you are going to have to reference the library's namespace as defined in your UserControl.

Something like this:

<UserControl x:Class="PBA.Application.Client.UserControls.UserControls.FreqReserve.OverView"
             ...
             xmlns:local="clr-namespace:PBA.Application.Client.UserControls.UserControls">

    ...
       <DockPanel>
        <UserControls:LegendControl>
            <UserControls:LegendControl.Items>
                <UserControls:LegendItem IsVisible="{Binding Path=IsDirtyVisible, 
                    RelativeSource={RelativeSource Mode=FindAncestor, 
                                    AncestorType={x:Type local:FreqReserve.OverView}}}" 
                    Identifier="Pink" 
                    Text="Ikke sendt"></UserControls:LegendItem>

               ....         

        </UserControls:LegendControl>
    </DockPanel>
</UserControl>

Note that you will have to put the correct namespace for the "local" declaration, but you should get that from IntelliSense if you aren't sure what it should be.

Wonko the Sane
Sorry. Went a bit too far while removing fluff and wrote a bit of the code by hand as it is no longer in the actual code. Snippet updated to better reflect actual code.
hhravn
Let's start simple, and work our way out. Is IsDirtyVisible a property of the OverView control?
Wonko the Sane
Yep, its a wrapped dependencyproperty.
hhravn
What does that property and DP look like?
Wonko the Sane
private static readonly DependencyProperty _isDirtyVisibleProperty = DependencyProperty.Register("IsDirtyVisible", typeof (bool), typeof (OverView), new PropertyMetadata(true)); public bool IsDirtyVisible { get { return (bool)GetValue(_isDirtyVisibleProperty); } set { SetValue(_isDirtyVisibleProperty, value); } }
hhravn