0

これは以前に尋ねられました。私はいくつかのことを試し、多くの投稿を読みましたが、これを機能させることができません。ウィンドウが開き、 に列が表示されませんlistview。代わりに私は見るSystem.Windows.Controls.Gridview Columns=3

XAML とコード ビハインド。ViewModel必要に応じて投稿できます

XAML

<Window x:Class="DataBinding.LogFileWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:DataBinding"
        Title="LogFileWindow" Height="556.183" Width="717.987">
    <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
    <Grid>


                <TabPanel Margin="12,131,128.6,12.4" Width="Auto" Grid.RowSpan="2">
            <TabControl Margin="10,10,-270,-223.8">
                <TabItem Header="Logging Log">
                        <ListView Name="LoggingListView" ItemsSource="{Binding LogEntries}">
                            <GridView>
                                <GridViewColumn Header="Date" DisplayMemberBinding="{Binding Path=Date}"></GridViewColumn>
                                <GridViewColumn Header="Time" DisplayMemberBinding="{Binding Path=Time}"></GridViewColumn>
                                <GridViewColumn Header="Event" DisplayMemberBinding="{Binding Path=Event}"></GridViewColumn>
                            </GridView>
                        </ListView>
                </TabItem>
                <TabItem Header="Accounting Log">
                    <ListView Name="AccountingListView" ItemsSource="{Binding}" Margin="0,0,-14.6,38.2"></ListView>
                </TabItem>
                <TabItem Header="NVRAM Log">
                    <ListView Name="NVRAMListView" ItemsSource="{Binding}"></ListView>
                </TabItem>
            </TabControl>
        </TabPanel>

    </Grid>

C#

     public MainWindow()
        {   
            //create a new logging log file
            LoggingLog logfile = new LoggingLog();

            //add some entries
            // these are not real dates and times but that doesn't matter much.


            for (int i = 0; i < 20; i++)
            {
                LogFileEntry le = new LogFileEntry();
                le.Date = String.Format("Date{0}", i);
                le.Time = String.Format("Time{0}", i);
                le.Event = String.Format("Event{0}", i);
              logfile.LogEntryList.Add(le);
            }

            //now load the viewmodel

            LogViewModel logviewmodel = new LogViewModel();
            foreach (LogFileEntry le in logfile.LogEntryList)
            {
                logviewmodel.Add(new LogEntryViewModel(le));

            }

            //now set the datacontext on the window
            LogFileWindow lfwindow = new LogFileWindow();
            lfwindow.LogEntries = logviewmodel;
            lfwindow.LoggingListView.DataContext = logviewmodel;

            InitializeComponent();
            lfwindow.Show();
        }
4

1 に答える 1

0

上記の XAML は、GridView オブジェクトを ListView のコンテンツとして挿入します。したがって、ItemsSource をオーバーライドします。GridView を ListView のビューとして割り当てたい場合:

<ListView Name="LoggingListView" ItemsSource="{Binding LogEntries}">
    <ListView.View>
        <GridView>
           <GridViewColumn Header="Date" DisplayMemberBinding="{Binding Path=Date}"></GridViewColumn>
           <GridViewColumn Header="Time" DisplayMemberBinding="{Binding Path=Time}"></GridViewColumn>
           <GridViewColumn Header="Event" DisplayMemberBinding="{Binding Path=Event}"></GridViewColumn>
         </GridView>
    </ListView.View>
</ListView>
于 2012-10-31T01:41:35.947 に答える