파일을 목록보기로 읽고 목록보기에서 파일로 저장하는 간단한/표준 방법이 있습니까? TXT 파일, XAML 파일 또는 이진 파일 이건 상관하지 않습니다. 그것은 중요하지 않으며 많은 데이터가 없습니다. 여기 C#에서 ListView를 읽고 쓸 수있는 간단한 방법은 무엇입니까?
는 열과 listView1라는 각public class LVData
{
public string Name { get; set; }
public string YoungPic { get; set; }
public string MediumPic { get; set; }
public string AdultPic { get; set; }
public bool SaltWater { get; set; }
public bool FreshWater { get; set; }
public bool Grasslands { get; set; }
public bool Swamp { get; set; }
public bool TropicalForrest { get; set; }
public bool Forest { get; set; }
public bool ForestEdge { get; set; }
public bool Sand { get; set; }
public bool Coastal { get; set; }
public bool RiverBorder { get; set; }
public bool LakeBorder { get; set; }
public bool Floodplain { get; set; }
}
내 목록보기에 저장된 데이터입니다.
그리고 XAML : Listview image http://dinosaur-island.com/wordpress/wp-content/uploads/2013/06/Seeding-Plants.jpg나는 또한 추가 한 : 여기
<Window x:Class="DinosaurIsland.PlantDisplay"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:DinosaurIsland"
Title="Vegetation" Height="308" Width="1212" WindowStyle="SingleBorderWindow"
DataContext="{Binding RelativeSource={RelativeSource Self}}" Loaded="Window_Loaded">
<Window.Resources>
<DataTemplate x:Key="YoungPicCell">
<StackPanel Orientation="Horizontal">
<Image Height="200" Width="200" Stretch="None" Source="{Binding YoungPic}" />
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="MediumPicCell">
<StackPanel Orientation="Horizontal">
<Image Height="200" Width="200" Stretch="None" Source="{Binding MediumPic}" />
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="AdultPicCell">
<StackPanel Orientation="Horizontal">
<Image Height="200" Width="200" Stretch="None" Source="{Binding AdultPic}" />
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="TerrainCell">
<StackPanel Orientation="Vertical">
<CheckBox Content="Salt Water" Name="SaltWaterCheckbox" IsThreeState="False" IsChecked="{Binding Saltwater}" />
<CheckBox Content="Fresh Water" Name="FreshWaterCheckbox" IsThreeState="False" IsChecked="{Binding Freshwater}" />
<CheckBox Content="Grassland/Plains" Name="GrasslandsCheckbox" IsThreeState="False" IsChecked="{Binding Grassland}" />
<CheckBox Content="Swamp" Name="SwampCheckbox" IsThreeState="False" IsChecked="{Binding Swamp}" />
<CheckBox Content="Tropical Forest" Name="TropicalForestCheckbox" IsThreeState="False" IsChecked="{Binding TropicalForest}" />
<CheckBox Content="Forest" Name="ForestCheckbox" IsThreeState="False" IsChecked="{Binding Forest}" />
<CheckBox Content="Forest Edge" Name="ForestEdgeCheckbox" IsThreeState="False" IsChecked="{Binding ForestEdge}" />
<CheckBox Content="Sand" Name="SandCheckbox" IsThreeState="False" IsChecked="{Binding Sand}" />
<CheckBox Content="Coastal" Name="CoastalCheckbox" IsThreeState="False" IsChecked="{Binding Coastal}" />
<CheckBox Content="River Border" Name="RiverBorderCheckbox" IsThreeState="False" IsChecked="{Binding RiverBorder}" />
<CheckBox Content="LakeBorder" Name="LakeBorderCheckbox" IsThreeState="False" IsChecked="{Binding LakeBorder}" />
<CheckBox Content="Floodplain" Name="FloodplainCheckbox" IsThreeState="False" IsChecked="{Binding Floodplain}" />
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="PlacePlantsCell">
<StackPanel Orientation="Vertical">
<Label Margin="10" Content="Random" HorizontalAlignment="Center" ></Label>
<Slider Margin="10" Width="190" Value="50" Orientation="Horizontal" HorizontalAlignment="Center" IsSnapToTickEnabled="True" Maximum="100" TickPlacement="BottomRight" TickFrequency="5"> </Slider>
<Button Margin="10" Content="Randomly Seed Plants" HorizontalAlignment="Center" Height="23" Name="SeedButton" ></Button>
</StackPanel>
</DataTemplate>
</Window.Resources>
<DockPanel>
<Grid>
<ListView Name="listView1">
<ListView.View>
<GridView>
<GridViewColumn Width="152" Header="Name" DisplayMemberBinding="{Binding Name}" />
<GridViewColumn Width="202" Header="Picture of Young Plant" CellTemplate="{StaticResource YoungPicCell}" />
<GridViewColumn Width="202" Header="Picture of Medium Plant" CellTemplate="{StaticResource MediumPicCell}" />
<GridViewColumn Width="202" Header="Picture of Adult Plant" CellTemplate="{StaticResource AdultPicCell}" />
<GridViewColumn Width="202" Header="Terrain/Environments" CellTemplate="{StaticResource TerrainCell}" />
<GridViewColumn Width="202" Header="Place Plants" CellTemplate="{StaticResource PlacePlantsCell}" />
</GridView>
</ListView.View>
</ListView>
<Button Content="New Plant" DockPanel.Dock="Bottom" Height="23" HorizontalAlignment="Left" Margin="160,240,0,0" Name="NewPlant" VerticalAlignment="Top" Width="75" Click="NewPlant_Click" />
<Button Content="Save" DockPanel.Dock="Bottom" Height="23" HorizontalAlignment="Center" Margin="1099,240,15,0" Name="SavePlant" VerticalAlignment="Top" Width="75" Click="SavePlant_Click"/>
<Button Content="Load" Height="23" HorizontalAlignment="Left" Margin="26,240,0,0" Name="LoadPlants" VerticalAlignment="Top" Click="LoadPlants_Click" Width="75" />
</Grid>
</DockPanel>
그리고는 (그것이라고 무엇이든) 전체 양식/대화 상자/목록보기의 사진입니다 이 화면 캡을 찍은 후 '로드'버튼을 누릅니다.
작동하는지 알려주세요 : http://www.codeproject.com/Articles/26875/WPF-XmlDataProvider-Two-Way -Data-Binding 그래서 파일을 manuelly 파일에 복사 할 필요는 없습니다.이 파일을 저장하면됩니다. –
무엇? 귀하의 질문은 완전히 불분명합니다. 네, 원하는 데이터 저장소에 데이터를 저장할 수 있으며, 그 자체로는 WPF 나 프리젠 테이션 레이어/UI 요소/그 무엇과도 아무 관계가 없습니다. –
불명확해서 죄송합니다. 내가 헷갈 른 것은 어떻게 파일에 대한 목록 뷰의 각 항목을 작성한 다음 다시 읽는가입니다. 이 작업을 수행하는 '표준'방법이 있습니까? 난 그냥 txt 파일에 문자열로 각 행을 덤프하고로드 프로세스를 되돌릴 수있을 것 같아요. 나는 좀 더 우아한 것을 찾고 있었다. 예를 찾지 못했습니다. 또는 이것이 올바른 방법이라는 것을 알 수 없습니다. – zetar