Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Create Data Binding dialog woe’s

$
0
0

Using VS 2012 for a couple of months now I notice that the Data Binding Wizard doesn’t
work. I create a new WPF project and add a Text Block to the windows root Grid.

<Window x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:WpfApplication1"
    Title="MainWindow" Height="350" Width="525"><Grid ><TextBlock HorizontalAlignment="Center" VerticalAlignment="Center"  /></Grid></Window>

Then add a Dependency property of type String to the MainWindow class called BindToMe.

Class MainWindow 

#Region "  BindToMe property"
    Public Shared ReadOnly BindToMeProperty As DependencyProperty = DependencyProperty.Register("BindToMe",
                                                                                                  GetType(String),
                                                                                                  GetType(MainWindow),
                                                                                                  New FrameworkPropertyMetadata("Binding here folks", FrameworkPropertyMetadataOptions.AffectsRender,
                                                                                                                                New PropertyChangedCallback(AddressOf OnBindToMeChanged)))

    Shared Sub OnBindToMeChanged(ByVal sender As Object, ByVal e As DependencyPropertyChangedEventArgs)

    End Sub

    Public Property BindToMe As String
        Get
            Return CType(GetValue(BindToMeProperty), String)
        End Get
        Set(ByVal value As String)
            SetValue(BindToMeProperty, value)

        End Set
    End Property
#End Region

End Class

Build and select the root Grid and in the properties window click on the square to open the context menu for the Grids DataContext property, and select “Create Data Binding”. Then in the Create Data Bindings wizard I change the Binding Type to “RelativeSource FindAncestor”. This should list all of the Ancestors of the Grid but the list is blank. I check “Show all assemblies” and it gives me everything except the projects classes. In vs2010 it gives you all of the classes including the projects class.

Bummer I have to type the binding in by hand.

Then I select the TextBlock and open the Create Data Bindings wizard. I change the Binding type to Data context and it says that the data context is not set, although it is. This too also work beautifully in vs2010.

<Grid DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MainWindow}, AncestorLevel=1}}"><TextBlock Text="{Binding BindToMe}" HorizontalAlignment="Center" VerticalAlignment="Center"  /></Grid>

Am I missing something, is this a bug or did the VS team just water down one of the better features of Visual Studio?

Using VS 2012 Premium




Viewing all articles
Browse latest Browse all 18858

Trending Articles