在TemplateColumn中的WPF Visual Basic嵌套DataGrid

时间:2013-06-28 15:44:20

标签: vba wpfdatagrid

我是这个论坛的新手,也是编程方面的新人。

尽管如此,我还是去了一个使用WPF / Visual Basic的个人音乐播放器,在下面这个问题上非常(甚至)很长时间打了一场比赛:

相当于媒体播放器,我希望相应的艺术家位于相应的标题专辑封面和其他信息视图右侧的列表中。

为此,我有一个DataGrid(Master)用于解释的各个专辑 - 尽可能容易;现在从各自的歌曲细节中显示专辑封面,我需要有可能,在TemplateColumn ** **中另一个DataGrid(子)到“Nesting”,但我对Petrol Ofisi的看法

与此链接http://social.msdn.microsoft.com/Forums/vstudio/en-US/36909161-3afc-4fcc-af0a-da377a65e421/wpf-grid-column-databinding-to-comple中的解决方案非常接近的解决方案存在,但仅限于有限的程度,因为我可以理解,因为

  • 用C#编程,
  • 通过定义的Collection-Klassen进行数据绑定,最后但并非最不重要的是
  • 该解决方案使用转换器,其实现的问题对我来说真的很难。

    <Grid x:Name="LayoutRoot" HorizontalAlignment="Left" Margin="0,0,-7.6,-2.4" VerticalAlignment="Top" Width="1344.8" ScrollViewer.HorizontalScrollBarVisibility="Hidden" Height="790">
    <DataGrid x:Name="AlbenInterpretenAlbenDG" VirtualizingPanel.IsVirtualizing="True" VirtualizingPanel.IsVirtualizingWhenGrouping="True" VirtualizingPanel.VirtualizationMode="Recycling" CanUserAddRows="False" HorizontalAlignment="Left" Height="413.6" Margin="-7.2,362.4,0,0" Width="1345.2" BorderThickness="0" FontFamily="Baskerville Old Face" FontSize="26.667" Foreground="#FF2F3699" AutoGenerateColumns="False" VerticalAlignment="Top" HorizontalScrollBarVisibility="Hidden" IsReadOnly="True" Background="{x:Null}" MaxHeight="800" HorizontalGridLinesBrush="#FFFFC20E" IsSynchronizedWithCurrentItem="False" HeadersVisibility="None">
        <DataGrid.GroupStyle>
            <GroupStyle>
                <GroupStyle.HeaderTemplate>
                    <DataTemplate>
                        <TextBlock x:Name="GroupHeaderAlbum" Background="#FFFFC20E" Foreground="#FF2F3699" FontSize="40.333" FontFamily="Baskerville Old Face" FontWeight="Bold" FontStyle="Italic"/>
                    </DataTemplate>
                </GroupStyle.HeaderTemplate>
            </GroupStyle>
        </DataGrid.GroupStyle>
        <DataGrid.Columns>
            <DataGridTemplateColumn x:Name="AlbumCover" CanUserSort="True" CanUserReorder="False" ClipboardContentBinding="{x:Null}" SortMemberPath="Album.SortName" Header="AlbumCover" SortDirection="Ascending">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <Grid x:Name="GridAlbumCover" Background="#FFFFC20E" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Top" Width="190" Height="190">
                            <Image Source="{Binding AlbumcoverBildDatei}" Stretch="Fill" Height="180" Width="180" Margin="5,5,5,5"/>
                        </Grid>
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>
            <DataGridTextColumn x:Name="AlbumID" Binding="{Binding AlbumID}" ClipboardContentBinding="{x:Null}" FontSize="41.333" FontFamily="Baskerville Old Face" Header="AlbumID" Visibility="Hidden" d:IsHidden="True"/>
            <DataGridTextColumn x:Name="Album" Binding="{Binding Album}" ClipboardContentBinding="{x:Null}" FontSize="41.333" FontFamily="Baskerville Old Face" Header="Album" Visibility="Hidden" d:IsHidden="True"/>
            <DataGridTextColumn x:Name="Orchestra" Binding="{Binding Orchestra}" ClipboardContentBinding="{x:Null}" FontSize="41.333" FontFamily="Baskerville Old Face" Header="Orchestra" Visibility="Hidden" d:IsHidden="True"/>
            <DataGridTemplateColumn x:Name="AlbenInterpretenAlbenSongs" Header="" Visibility="Visible" CanUserReorder="False">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <DataGrid x:Name="AlbenInterpretenAlbenSongsDG" **Binding=??????** VirtualizingPanel.IsVirtualizing="True" VirtualizingPanel.IsVirtualizingWhenGrouping="True" VirtualizingPanel.VirtualizationMode="Recycling" CanUserAddRows="False" HorizontalAlignment="Left" Height="200" Margin="0,0,-169.6,-3.6" Width="1324.4" BorderThickness="0" FontFamily="Baskerville Old Face" FontSize="26.667" Foreground="#FF2F3699" AutoGenerateColumns="False" VerticalAlignment="Top" HorizontalScrollBarVisibility="Hidden" IsReadOnly="True" Background="{x:Null}" IsSynchronizedWithCurrentItem="True" MaxHeight="800" HorizontalGridLinesBrush="#FFFFC20E" VerticalGridLinesBrush="#FFFFC20E" HeadersVisibility="None">
                            <DataGrid.RowBackground>
                                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                    <GradientStop Color="#FFBCBEDC" Offset="0.085"/>
                                    <GradientStop Color="White" Offset="1"/>
                                </LinearGradientBrush>
                            </DataGrid.RowBackground>
                            <DataGrid.BorderBrush>
                                <SolidColorBrush Color="#FF688CAF" Opacity="0"/>
                            </DataGrid.BorderBrush>
                            <DataGrid.Columns>
                                <DataGridTextColumn x:Name="OrchestraDG" Binding="{Binding Orchestra}" ClipboardContentBinding="{Binding Orchestra}" FontSize="37.333" FontFamily="Baskerville Old Face" Header="Album-Interpret" SortMemberPath="Orchestra" CanUserSort="True" Visibility="Hidden" Width="370"/>
                                <DataGridTextColumn x:Name="AlbumIDDG" Binding="{Binding AlbumID}" ClipboardContentBinding="{Binding AlbumID}" FontSize="41.333" FontFamily="Baskerville Old Face" Header="AlbumID" SortMemberPath="AlbumID" CanUserSort="True" Visibility="Hidden"/>
                                <DataGridTextColumn x:Name="AlbumNameDG" Binding="{Binding Album}" ClipboardContentBinding="{Binding Album}" FontSize="41.333" FontFamily="Baskerville Old Face" Header="Album" SortMemberPath="Alben.SortName" CanUserSort="True" Width="190" Visibility="Hidden"/>
                                <DataGridTextColumn x:Name="NrDG" Binding="{Binding Track}" ClipboardContentBinding="{Binding Track}" FontSize="41.333" FontFamily="Baskerville Old Face" Header="Nr." SortMemberPath="Track" CanUserSort="True" Width="50">
                                    <DataGridTextColumn.CellStyle>
                                        <Style>
                                            <Setter Property="Block.TextAlignment" Value="Right"/>
                                        </Style>
                                    </DataGridTextColumn.CellStyle>
                                </DataGridTextColumn>
                                <DataGridTextColumn x:Name="SongTitelDG" Binding="{Binding Title}" ClipboardContentBinding="{Binding Title}" FontSize="41.333" FontFamily="Baskerville Old Face" Header="Song-Titel" Width="505"/>
                                <DataGridTextColumn x:Name="InterpretDG" Binding="{Binding Artist}" ClipboardContentBinding="{Binding Artist}" FontSize="37.333" FontFamily="Baskerville Old Face" Header="Interpret" Width="380"/>
                                <DataGridTextColumn x:Name="LängeDG" Binding="{Binding Length, StringFormat=m:ss}" ClipboardContentBinding="{Binding Length}" FontSize="37.333" FontFamily="Baskerville Old Face" Header="Länge" Width="90">
                                    <DataGridTextColumn.CellStyle>
                                        <Style>
                                            <Setter Property="Block.TextAlignment" Value="Right"/>
                                        </Style>
                                    </DataGridTextColumn.CellStyle>
                                </DataGridTextColumn>
                                <DataGridTextColumn x:Name="JahrDG" Binding="{Binding SongsAlben/ErscheinungsJahr}" ClipboardContentBinding="{Binding ErscheinungsJahr}" FontSize="37.333" FontFamily="Baskerville Old Face" Header="Jahr" Width="100">
                                    <DataGridTextColumn.CellStyle>
                                        <Style>
                                            <Setter Property="Block.TextAlignment" Value="Right"/>
                                        </Style>
                                    </DataGridTextColumn.CellStyle>
                                </DataGridTextColumn>
                            </DataGrid.Columns>
                        </DataGrid>
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>
        </DataGrid.Columns>
    </DataGrid>
    
    Public Function GetAbfrageAlbenInterpretenAlbenSongs() As DataTable
    Dim adapter As New OleDbDataAdapter("Select * From AbfrageAlbenInterpretenAlbenSongs ORDER BY AbfrageAlbenInterpretenAlben.AlbenInterpreten.SortName, AbfrageAlbenInterpretenAlben.Alben.SortName, Songs.Track", Application.con)
    Dim AbfrageAlbenInterpretenAlbenSongsDataSet As New DataSet()
    adapter.Fill(AbfrageAlbenInterpretenAlbenSongsDataSet, "AbfrageAlbenInterpretenAlbenSongs")
    Return AbfrageAlbenInterpretenAlbenSongsDataSet.Tables(0)
    Application.con.Close()
    

    结束功能

    Private Sub PageAlbumInterpret_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs)
    

Dim AlbenInterpretenAlbenDS As DataSet AlbenInterpretenAlbenDS = GetAbfrageAlbenInterpretenAlbenSongs() ' Set the DataContext of AlbenInterpretenAlbenDG to DataTable AlbenInterpretenAlbenDG.DataContext = AlbenInterpretenAlbenDS.Tables(0) AlbenInterpretenAlbenDG.ItemsSource = AlbenInterpretenAlbenDS.Tables(0).DefaultView

End Sub

    Private Sub Artist_TextChanged(ByVal sender As Object, ByVal e As System.Windows.Controls.TextChangedEventArgs)

    'ALBEN UND SONGS
    Dim cvAlben As BindingListCollectionView = CType(CollectionViewSource.GetDefaultView(AlbenInterpretenAlbenDG.ItemsSource),BindingListCollectionView)
    CVAlben.CustomFilter = "Orchestra = '" & Artist.Text.Replace("'", "''") & "' Or Orchestra Like '" & Artist.Text.Replace("'", "''") & ";%' Or Orchestra Like '%; " & Artist.Text.Replace("'", "''") & ";%' Or Orchestra Like '%; " & Artist.Text.Replace("'", "''") & "'"
    Dim ArtistString As String
    ArtistString = Me.Artist.Text
    Dim DRV As DataRowView
    For Each DRV In AlbenInterpretenAlbenDG.Items
        If ArtistString = DRV("Orchestra") Then
            AlbenInterpretenAlbenDG.GroupStyle.Item(0) = CType(PageAlbumInterpret.FindResource("GroupHeaderStyleAlbum"), GroupStyle)
        Else
           AlbenInterpretenAlbenDG.GroupStyle.Item(0) = CType(PageAlbumInterpret.FindResource("GroupHeaderStyleOrchestraAlbum"), GroupStyle)
            Exit Sub
        End If
    Next
    CVAlben.MoveCurrentToFirst
    Dim border As Decorator = VisualTreeHelper.GetChild(AlbenInterpretenAlbenDG, 0)
    If border IsNot Nothing Then
        Dim scrollViewer As ScrollViewer = border.Child
        scrollViewer.ScrollToTop()
    End If

0 个答案:

没有答案