C# 将ObservableCollection(或LinkedList)绑定到WrapPanel的WPF数据
嗯。首先,我看了一大堆其他的问题和互联网上很多其他的地方,关于如何做到这一点,但没有一个是有帮助的,所以请不要把这标记为重复的,还有,请注意,因为我可能犯了一个非常愚蠢的错误 我正在尝试使用C# 将ObservableCollection(或LinkedList)绑定到WrapPanel的WPF数据,c#,wpf,xaml,data-binding,properties,C#,Wpf,Xaml,Data Binding,Properties,嗯。首先,我看了一大堆其他的问题和互联网上很多其他的地方,关于如何做到这一点,但没有一个是有帮助的,所以请不要把这标记为重复的,还有,请注意,因为我可能犯了一个非常愚蠢的错误 我正在尝试使用ItemsControl和DataTemplate将observateCollection绑定到WrapPanel。以下是我的XAML代码: <ItemsControl x:Name="wPanel"> <ItemsControl.ItemsPanel> <
ItemsControl
和DataTemplate
将observateCollection
绑定到WrapPanel
。以下是我的XAML代码:
<ItemsControl x:Name="wPanel">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<!--<Border BorderBrush="DarkGray" Background="Transparent">-->
<StackPanel MinWidth="250">
<Grid>
<TextBlock Text="{Binding address}" />
</Grid>
<Grid>
</Grid>
</StackPanel>
<!--</Border>-->
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
属性类包括以下属性和更多属性:
private string address { get; set; }
private string city { get; set; }
private string postcode { get; set; }
private double price { get; set; }
private LinkedList<Tennant> tennants { get; set; }
...
但是,xaml中的行:
不起作用
然后我得出结论,它与properties对象有关,除非通过代码实现,否则它不会绑定
我做错了什么,因为它没有通过XAML等绑定。?关于properties对象我需要更改什么,或者我需要做什么
提前谢谢。属性不是窗口上的属性吗? 如果要在xaml中绑定,请确保将“属性”声明为“属性”,将窗口的datacontext设置为自身,然后设置绑定路径:-
<ItemsControl x:Name="wPanel" ItemsSource="{Binding properties}">
this.DataContext=this; //set datacontext on parent window or control
“属性”不是窗口上的属性吗? 如果要在xaml中绑定,请确保将“属性”声明为“属性”,将窗口的datacontext设置为自身,然后设置绑定路径:-
<ItemsControl x:Name="wPanel" ItemsSource="{Binding properties}">
this.DataContext=this; //set datacontext on parent window or control
“属性”不是窗口上的属性吗? 如果要在xaml中绑定,请确保将“属性”声明为“属性”,将窗口的datacontext设置为自身,然后设置绑定路径:-
<ItemsControl x:Name="wPanel" ItemsSource="{Binding properties}">
this.DataContext=this; //set datacontext on parent window or control
“属性”不是窗口上的属性吗? 如果要在xaml中绑定,请确保将“属性”声明为“属性”,将窗口的datacontext设置为自身,然后设置绑定路径:-
<ItemsControl x:Name="wPanel" ItemsSource="{Binding properties}">
this.DataContext=this; //set datacontext on parent window or control
这是检查
绑定的简单技巧。每个WPF开发人员都必须知道这一点。例如:
<TextBlock Text="{Binding}" />
跑去看看
如果TextBlock
在DataContext中有任何对象,则在TextBlock中显示对象类名。
如果DataContext
为空。TextBlock为空
这是检查绑定的简单技巧。每个WPF开发人员都必须知道这一点。例如:
<TextBlock Text="{Binding}" />
跑去看看
如果TextBlock
在DataContext中有任何对象,则在TextBlock中显示对象类名。
如果DataContext
为空。TextBlock为空
这是检查绑定的简单技巧。每个WPF开发人员都必须知道这一点。例如:
<TextBlock Text="{Binding}" />
跑去看看
如果TextBlock
在DataContext中有任何对象,则在TextBlock中显示对象类名。
如果DataContext
为空。TextBlock为空
这是检查绑定的简单技巧。每个WPF开发人员都必须知道这一点。例如:
<TextBlock Text="{Binding}" />
跑去看看
如果TextBlock
在DataContext中有任何对象,则在TextBlock中显示对象类名。
如果DataContext
为空。TextBlock是空的
您可以将ItemsControl的ItemsSource绑定到属性,就像@AjS answer一样。但在此之前,您需要将属性声明更改为属性而不是字段
public ObservableCollection<Property> properties { get; set; }
您可以将ItemsControl的ItemsSource绑定到属性,就像@AjS answer一样。但在此之前,您需要将属性声明更改为属性而不是字段
public ObservableCollection<Property> properties { get; set; }
您可以将ItemsControl的ItemsSource绑定到属性,就像@AjS answer一样。但在此之前,您需要将属性声明更改为属性而不是字段
public ObservableCollection<Property> properties { get; set; }
您可以将ItemsControl的ItemsSource绑定到属性,就像@AjS answer一样。但在此之前,您需要将属性声明更改为属性而不是字段
public ObservableCollection<Property> properties { get; set; }