WPF Binding Path=/ not working?

谁说我不能喝 提交于 2019-12-06 01:57:28

Try ItemsSource="{Binding}". It should be enough.

In response to the OP's question of why {Binding} works, but {Binding Path=/} does not work, I'm adding the following info as an answer to clarify the difference.

The following is taken from MSDN Data Binding Overview > Binding to Collections:

Current Item Pointers

Views also support the notion of a current item. You can navigate through the objects in a collection view. As you navigate, you are moving an item pointer that allows you to retrieve the object that exists at that particular location in the collection. For an example, see How to: Navigate Through the Objects in a Data CollectionView.

Because WPF binds to a collection only by using a view (either a view you specify, or the collection's default view), all bindings to collections have a current item pointer. When binding to a view, the slash ("/") character in a Path value designates the current item of the view. In the following example, the data context is a collection view. The first line binds to the collection. The second line binds to the current item in the collection. The third line binds to the Description property of the current item in the collection.

<Button Content="{Binding }" />
<Button Content="{Binding Path=/}" />
<Button Content="{Binding Path=/Description}" />

As an alternative sol'n to Danko's answer, I discovered Static Resources! (I'm a WPF noob)

<Window x:Class="ImageGetGUI.MainWindow"
    ...
    <Window.Resources>
        <c:DownloadManager x:Key="dm"/>
    </Window.Resources>
    ...
    <DataGrid Name="dataGrid1" ItemsSource="{StaticResource dm}" ...
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!