嗨試圖將我的應用程序遷移到WPF,並且我試圖儘可能多地保留MVVM。從我的WinForm應用程序的以下屏幕相當容易創建,我沒有Xaml和WPF這樣的好運氣。使用ListView的WPF UI從Csv文件映射自定義字段
我喜歡它是如何工作的,但我的目標是要麼與WPF重新創建,或做這個字段映射某種程度上,我沒有考慮過的,仍然滿足的基本要求將輸入字段映射到我現有的數據結構。
目前這是我在Xaml中的。
<UserControl x:Class="ImportJobDataView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:kne="clr-namespace:FatigueMVVM"
xmlns:local="clr-namespace:FatigueMVVM.DragDropListBox"
mc:Ignorable="d" d:DesignHeight="350" d:DesignWidth="447">
<Grid Height="350" Width="448">
<Grid.RowDefinitions >
<RowDefinition Height="300" />
<RowDefinition Height="50" />
</Grid.RowDefinitions>
<ListView ItemsSource="{Binding ImportedJobDataColumns}" Margin="37,68,295,64" local:DragDropHelper.IsDragSource="true">
<ListView.View >
<GridView AllowsColumnReorder="True" >
<GridViewColumn Width="100" Header="Imported"/>
</GridView>
</ListView.View>
</ListView>
<ListView ItemsSource="{Binding KneJobDataColumns}" Margin="193,68,41,64" AllowDrop="True" local:DragDropHelper.IsDropTarget="true">
<ListView.View >
<GridView AllowsColumnReorder="True" >
<GridViewColumn Width="100" Header="Import From" DisplayMemberBinding="{Binding ImportField }" />
<GridViewColumn Width="100" Header="Map To" DisplayMemberBinding="{Binding KneField }" />
</GridView>
</ListView.View>
</ListView>
<Button Content="Open Csv" Height="23" HorizontalAlignment="Left" Margin="37,15,0,0" Name="Button1" VerticalAlignment="Top" Width="75" Command="{Binding OpenCsvCommand}" Grid.Row="1" />
<Button Content="Clean Data" Height="23" HorizontalAlignment="Left" Margin="118,15,0,0" Name="Button2" VerticalAlignment="Top" Width="auto" Grid.Row="1" />
<Button Content="View Imported Data" Height="23" HorizontalAlignment="Left" Margin="193,15,0,0" Name="Button3" VerticalAlignment="Top" Width="auto" Grid.Row="1" />
</Grid>
這看起來接近我喜歡它的樣子,但我不能讓拖放工作。正如您可能已經注意到的那樣,我正在使用Bea Stollnitz解決方案嘗試實施拖放操作。 http://bea.stollnitz.com/blog/?p=53她的解決方案只能用於ItemsControls,因此恐怕它不適用於我用來創建兩列的GridView。我已經試過了,只是Listboxes和拖放功能確實工作,但我真的需要兩列才能做到這一點。
有誰要麼就如何落實在這種情況下拖放一個建議,或者我目前想實現這個方式的替代方案。
非常感謝!
感謝雷切爾,我終於實現了在代碼隱藏的拖放特定的功能,我結束了使用數據網格。我會發布我的代碼和更多細節,因爲它可能會幫助別人,Snoop非常酷! – GetFuzzy 2012-07-21 20:40:36