0

I am trying to bind my design data to a single property (Margin) in a Grid. I do not want to overwrite the data context for the grid as a whole (which is also using design data.

<Grid 
  d:DataContext="{d:DesignData Source=/Blend/DesignData/HudDesignData.xaml}" 
  Margin="{Binding Source={d:DesignData Source=/Blend/DesignData/WPFSplitScreenLayoutDesignData.xaml}}">

The design data being set to DataContext works as expected.

d:DataContext="{d:DesignData Source=/Blend/DesignData/HudDesignData.xaml}"

However, I can't figure out how the assign design data as the Binding Source of Margin directly.

Margin="{Binding Source={d:DesignData Source=/Blend/DesignData/WPFSplitScreenLayoutDesignData}}"

The line above gives the following error:

Error 1 The tag 'DesignData' does not exist in XML namespace 'http://schemas.microsoft.com/expression/blend/2008'. Line 13 Position 135.

Thanks!

Goose
  • 1,307
  • 2
  • 14
  • 28

1 Answers1

0

Are you jsut missing the .xaml from wpfsplitscreenlayotudesigndata ?

Or you bind the margin to a property on your view model then from the view model find the wpfsplitscreenlayoutdesigndata that you wanted.

Margin="{Binding Path = someint}"

int someint
{
    get
    { 
       //return the wpfspliscreenlayoutdesigndata which I assume you are getting from the visual tree
    }
} 
Chris
  • 915
  • 8
  • 28
  • The missing .xaml was a typo. Fixed. I don't think your suggestion would work, as the point of design data is to have "design time" specific data without affecting runtime. In your example you are changing the runtime binding of Margin. – Goose Mar 27 '14 at 17:18
  • Margin="{Binding Source={d:DesignData Source=/Blend/DesignData/WPFSplitScreenLayoutDesignData.xaml}, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" Give that a go – Chris Mar 27 '14 at 17:23