完全做到這是我的XAML參與WPF綁定...要使用XAML
public class Component
{
private ObservableCollection<ComponentParameter> parameters = new ObservableCollection<ComponentParameter>();
public string Name
{
get;
set;
}
public ObservableCollection<ComponentParameter> Parameters
{
get{return parameters;}
set{parameters = value;}
}
}
public class ComponentParameter
{
public string Name
{
get;set;
}
public string Value
{
get;set;
}
public bool HasErrors
{
get;
set;
}
public bool IsDuplicate
{
get; set;
}
public bool IsMissing
{
get;set;
}
的
ListView
<ListView x:Name="duplicateVarsInCompXMLListView" ItemsSource="{Binding}" HorizontalAlignment="Left" VerticalAlignment="Top" Width="306">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<TextBlock Text="ComponentID: " FontWeight="Bold" Foreground="Brown" />
<TextBlock Text="{Binding Name}"/>
</StackPanel>
<ItemsControl ItemsSource="{Binding Parameters}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Variable Name: " Foreground="Green"/>
<TextBlock Text="{Binding Name}"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Variable Value: " Foreground="Blue"/>
<TextBlock Text="{Binding Value}"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
代碼隱藏
private ObservableCollection<Component> mastercomponentcollection;
mastercomponentcollection = //code to populate the collection
duplicateVarsInCompXMLListView.DataContext = this.mastercomponentcollection;
類
在這裏,我想僅顯示那些IsDuplicate
設置爲true的收集項的綁定。我相信DataTemplate.Triggers
是要走的路,但我無法弄清楚使其工作的確切語法。有什麼建議麼?
我沒有得到它..只是爲了澄清你只想顯示那些ComponentParameter在你ItemsControl它有IsDuplicate爲真? – Nitin
@Omribitan感謝您的鏈接,我會研究它。 – Sike12
@nit正好...感謝您的時間 – Sike12