3

I am defining the RelativeSource in my Template in the XAML, with

DataContext="{Binding RelativeSource={RelativeSource Self}}"

I am getting an exception

"A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll

Additional information: Provide value on 'System.Windows.Markup.StaticResourceHolder' threw an exception."

I think the problem is i need to bind this after my Window.Resources declarations but i am not sure how to do this using the <DataContext tags and still use RelativeSource. Thanks!

<Window x:Class="SupportDesk.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Top Echelon Support Desk" Height="554" Width="743" xmlns:my="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit" xmlns:myNewNamespace="clr-namespace:SupportDesk"
    DataContext="{Binding RelativeSource={RelativeSource Self}}">
<Window.Resources>
    <myNewNamespace:BoolToVisibilityConverter x:Key="boolToVis" />

    <Style TargetType="{x:Type TextBlock}"
  x:Key="GridBlockStyle">
        <Setter Property="VerticalAlignment" Value="Center" />
        <Setter Property="Visibility"
 Value="{Binding Path=IsSelected,
     RelativeSource={RelativeSource FindAncestor,
         AncestorType={x:Type ListViewItem}},
     Converter={StaticResource boolToVis},
         ConverterParameter=False}" />
    </Style>
</Window.Resources>
4
  • I thin you are going to have to give more details. Can you provide a few snippets of code? Commented Dec 22, 2010 at 13:44
  • sure, here is my information in the xaml: Commented Dec 22, 2010 at 13:51
  • hmm, what would be the best way to post this? Commented Dec 22, 2010 at 13:51
  • just from researching online i think the reason the exception is occurring is because of the RelativeSource declaration is before my Window.Resources section. but every where i have looked the Relative source is always bound to specific elements, whereas i have three autocompleteboxes i am using from the WPF Toolkit, that reference this. i would like to delcare this using the datacontext tags but i dont think this is possible. Commented Dec 22, 2010 at 13:58

1 Answer 1

3

How about setting the DataContext on the immediate child of your window? e.g.

<Window>
   <Grid DataContext="{Binding RelativeSource={RelativeSource Self}}">
   </Grid>
</Window>

Would this work for you?

Sign up to request clarification or add additional context in comments.

5 Comments

thanks for helping with this. the exception is gone when i do that however now no data is returning in my listview. basically i have three autocomplete boxes, and when a value is selected i run a query and return results in a listview. the data is no longer being returned
Time to do a bit of debugging! ... i you set a breakpoints, what is the DataContext for the listview? for the Grid? ...
Also ... why are you using a relative source self binding? Typically this is used for UI controls, not windows / forms.
i am not really sure. what should i be using?
well either way it was working until my recent problem which stemmed from my trying allow for editing a field in the listview. thanks for the suggestion, ill figure it out ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.