relativesource

How do I use WPF bindings with RelativeSource?

How do I use RelativeSource with WPF bindings and what are the different use-cases? ...

How do you debug wpf relativesource throwing errors on load?

I'm working with a WPF dialog window that contains a ListBox. The list box can display both an 'icon' and 'list' view. To accomplish this, we used ListBoxItem styles that are dynamically applied to the ListBox, as well as a pair of corresponding ItemsPanelTemplates. As is, it displays beautifully. However, when loading this dialog we ge...

Differences between ElementName="<Me>" and RelativeSource self?

What are the differences between making a binding self-referential via name versus self-referential via RelativeSource? For example: <!-- Self referential via name --> <Window ... x:Name="This" DataContext="{Binding Path=Data, ElementName=This}" > versus <!-- Self referential via RelativeSource --> <Window ... ...

Get DataContext of ListView Ancestor

I am developing a WPF app using MVVM and need some help. for the View of my AddressesViewModel I have a usercontrol with a listview. I would like to execute a command found in the AddressesViewModel from the contextmenu of the listViewItem. Because I'm opening a ContextMenu it is not found in the visual tree(I read that somewhere). He...

WPF TemplateBinding vs RelativeSource TemplatedParent

What is the difference between <ControlTemplate TargetType="{x:Type Button}" x:Key="buttonTemplate"> <Border BorderBrush="{TemplateBinding Property=Background}" BorderThickness="3" > <ContentPresenter Margin="10"/> </Border> </ControlTemplate> and <ControlTemplate TargetType="{x:Type Button}" x:Key="buttonTemplate"> ...

WPF RelativeSource binding question

HI! I have an Expander and a TextBox. I want to disable the TextBox when the Expander is expanded and enable when it's not expanded. How to do that? I've tried something like this: <TextBox IsEnabled="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Expander}, AncestorLevel=1},Path=IsExpanded}" /> But it's vi...

[WPF] RelativeSource FindAncestor issue

Here is the code: <GridViewColumn DisplayMemberBinding="{Binding Path=BookId}" Width="100"> <GridViewColumn.Header> <Border BorderBrush="Black"> <TextBlock Width="{Binding RelativeSource...

WPF UserControl Command Parameter Binding to an object on the Parent

Hi, I have a UserControl Tasks.xaml that is used within a couple of property pages that inherit from a PropertyPageBase class - which itself inherits from UserControl. Within the Tasks UserControl, I want to use a Context menu command and the CommandParameter needs to bind to a DependencyProperty called Data on the PropertyPageBase cla...

What exactly does WPF Data Binding's "RelativeSource FindAncestor" do?

I am currently working within a WPF user control (the root element of my XAML file is "UserControl"), which I know is being hosted inside a Window. How can I access a property of the Window using data binding? Does anyone know why simply <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type Window}}" Path="..." />...

WPF ComboBox DropDown using PlacementTarget

I have a ContentControl comprised from left to right of a Button, partition and a ComboBox. I want the ComboBox dropdown to line up with the left side of the control as opposed to the left side of the combobox. I received a method in code but I was wondering whether if it could be accomplished in xaml. This gives me the name of the con...

WPF Bind to DependencyProperty of another Object?

Hi All, I am working on a WPF application similar to visio. I would like to be able to logically group some of the items in my diagram, each of which is a UIElement, and control certain behaviors (i.e. visibility) at the group level. My first attempt at this was to create a control, called a Group, which had width & height = 0. I w...

Silverlight 4 RelativeSource FindAncestor binding

Will there be RelativeSource FindAncestor, AncestorType... in Silverlight 4? ...

How to get relative source of item in ItemTemplate

I have a ListBox with specified ItemTemplate. And the ItemTemplate contain itself ListView and I want to display in that ListView a collection, which is actually a property of the item of the ListBox. Could you show me how to do Binding. I'm thinking about RelativeSource thing, but I don't know what correct syntax would look like... ...

Binding to a RelativeSource Self in Silverlight

Hello, I am trying to bind a value of a slider control to a property that is in the same control: <Slider Value="{Binding Path=ValueProperty, RelativeSource={RelativeSource Self}}" Name="slider1" /> but it doesn't bind to a "ValuePropery"... What am I doing wrong? ...

Silverlight RelativeSource of TemplatedParent Binding within a DataTemplate, Is it possible?

I'm trying to make a bar graph Usercontrol. I'm creating each bar using a DataTemplate. The problem is in order to compute the height of each bar, I first need to know the height of its container (the TemplatedParent). Unfortunately what I have: Height="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Height, Converter={...

WPF: Binding to ObservableCollection in ControlTemplate is not updated

I created a ControlTemplate for my custom control MyControl. MyControl derives from System.Windows.Controls.Control and defines the following property public ObservableCollection<MyControl> Children{ get; protected set; }. To display the nested child controls I am using an ItemsControl (StackPanel) which is surrounded by a GroupBox. If...

WPF - RelativeSource Binding Problem

Hi All, I am trying to create a back button. So i am binding the navigationwindows backstack. Code: <Hyperlink Name="back" NavigateUri="{Binding RelativeSource={RelativeSource AncestorType={x:Type NavigationWindow}}, Path=BackStack}"> Problem: Error: Mode must be specified for RelativeSource. Update: It is not navigation to th...

Binding with Relativesource --wpf

Hi, I have a short question: I have a datagrid and binded it to something. Then I put a combobox in a column and binded it to another source by ItemsSource="{Binding DataContext.Users, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}}" Now I want to use datagrid's source again, in the combobox again.That...

WPF Bind to parent property from within nested element using style

Hi, I've been trying to build a text box with a hint that's displaying while it's empty. I'm having trouble setting the hint text from within a style. To be precise, this works (that is, it binds correctly): <TextBox Tag="hint text"> <TextBox.Background> <VisualBrush Stretch="None"> <VisualBrus...

RelativeSource binding from a ToolTip or ContextMenu

What am I doing wrong here?: <GridViewColumn> <GridViewColumn.CellTemplate> <DataTemplate> <Button> <Button.ToolTip> <TextBlock Text="{Binding Path=Title, RelativeSource={RelativeSource AncestorType=Window}}" /> That's just a simplified example, that doesn't work anyway :) Actually I ne...