views:

110

answers:

2

Hi,

FindAncestor RelativeSource only supports 'Self' and 'TemplatedParent', but I have to bind the width of a popup to the width of the page.

Giving the page a name causes problems because sometimes it will throw exceptions saying a control with that name is already present in the visual tree.

<Popup IsOpen="True"
       Width="{Binding ElementName=BordPage, Path=Width}"
       Height="{Binding ElementName=BordPage, Path=Height}">

Background information:

I'm using a SL4 navigation based application here. BordPage is a navigation page, which I'm using multiple times within the application. So giving it a name in the page itself is not really a good idea, but I don't know how else I can bind to the width and height of the page.

What I'm trying to do is have a black border (with opacity 0.8) cover the entire screen, (including the controls of the MainPage). Then on top of that I want to display some other controls.

Since the application is touch controlled, providing the user with a ComboBox to select a value doesn't really work wel. Instead I want to show this black overlay window with a listbox taking up most of the screen so the user can simply touch the value he wants with a single click.

Update: I just realized I can use the ChildWindow class to do this. But my original question remains.

+1  A: 

My general solution for this problem is by writing a custom behavior. It's not a pure XAML solution but it gives you a lot more flexibility.

Create a behavior that searches up the VisualTree to find the right item and then have it set the width of the Popup correctly.

It may be a little more complicated than a straight binding but it avoids all the naming issues.

Stephan
A: 

Put the following in the constructor of your control so you can avoid naming it:

DataContext = this;
David Allen