我在我的xaml中對此進行了格式化,我的listView。這工作,但我要補充的模式複雜的邏輯,這樣這有所以現在我需要在代碼中應用上面的代碼背後施加ListView如何在代碼隱藏中而不是在xaml中更改ItemsPanel
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation = "Horizontal" Width = "250" Background = "{x:Null}" VerticalAlignment = "Top"></WrapPanel>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
。
---編輯馬蒂諾BORDIN ---
請告訴我,我有誤解:
1A。我在我的列表視圖定義的風格:
<ListView x:Name="lvPPtab1" Grid.Row="2" FontSize="12" Background="{x:Null}" BorderBrush="Gainsboro" BorderThickness="5" Margin="10,12.2,10,8.4" VerticalAlignment="Stretch" PreviewMouseLeftButtonDown="ListBox_PreviewMouseLeftButtonDown" SelectionChanged="ListView_SelectionChanged">
<ListView.Resources>
<Style x:Key="ListViewStyle" TargetType="ListView">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate >
<WrapPanel Orientation="Horizontal" VerticalAlignment="Top"/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</Style>
</ListView.Resources>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="Blue"/>
</Trigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
</ListView>
2a.I設置它在我的代碼僅落後時,我需要它:
<ListView x:Name="lvPPtab1" Grid.Row="2" FontSize="12" Background="{x:Null}" BorderBrush="Gainsboro" BorderThickness="5" Margin="10,12.2,10,8.4" VerticalAlignment="Stretch" PreviewMouseLeftButtonDown="ListBox_PreviewMouseLeftButtonDown" SelectionChanged="ListView_SelectionChanged">
<ListView.Resources>
<Style x:Key="ListViewStyle" TargetType="ListView">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate >
<WrapPanel Orientation="Horizontal" VerticalAlignment="Top"/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</Style>
</ListView.Resources>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="Blue"/>
</Trigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
</ListView>
lvPPtab1.Style = (Style)this.Resources["ListViewStyle"];
和所有我看到的是什麼就是什麼都沒有的ListView空。
然後我試圖堅持你說的話,所以我這樣做:
1b。在XAML
<ListView x:Name="lvPPtab1" Grid.Row="2" FontSize="12" Background="{x:Null}" BorderBrush="Gainsboro" BorderThickness="5" Margin="10,12.2,10,8.4" VerticalAlignment="Stretch" PreviewMouseLeftButtonDown="ListBox_PreviewMouseLeftButtonDown" SelectionChanged="ListView_SelectionChanged">
<ListView.Resources>
<ItemsPanelTemplate x:Key="ListViewStyle" >
<WrapPanel Orientation="Horizontal" VerticalAlignment="Top"></WrapPanel>
</ItemsPanelTemplate>
</ListView.Resources>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="Blue"/>
</Trigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
</ListView>
-
在後面的代碼
:
lvPPtab1.ItemsPanel =(ItemsPanelTemplate)this.Resources [ 「ListViewStyle」];
但是再次沒有!所有的空我在哪裏錯了?
什麼代碼是什麼邏輯。可以請你告訴我們你想要達到什麼目標? – Rohit
你可以在我之前的問題中找到一切:http://stackoverflow.com/questions/36579473/continuation-to-how-can-i-programmatically-create-a-listview-full-of-strings-co?noredirect = 1#comment60762700_36579473 – Patrick
我以前試過沒有運氣。 – adminSoftDK