0

I have a datacontext object that displays a list of uploaded files, and number of copies. So far, the user can click an edit icon that is in each row, and retrieve the data in that row, but I do not know how to change any data.

Here is the button event for the 'change details' dialog on the main page:

    private void Image_MouseLeftButtonUp_1(object sender, MouseButtonEventArgs e)
    {
        Image b = sender as Image;
        FileReceivedItem fi = b.DataContext as FileReceivedItem;
        string fileCopies = fi.fileCopies;
        string fileName = fi.FileName;
        DetailsWindow detailsDlg = new DetailsWindow(fileCopies, fileName);
        detailsDlg.Show();
        detailsDlg.Closed += new EventHandler(detailsWnd_Closed);
    }

    public DetailsWindow detailsDlg;
    void detailsWnd_Closed(object sender, EventArgs e)
    {
        MessageBox.Show("I want to change fileCopies here");
    }

The relevant portions of the XAML:

    <ListBox ScrollViewer.HorizontalScrollBarVisibility="Hidden"  ItemsSource="{StaticResource FileReceivedItem}"  Name="filesReceivedList" HorizontalAlignment="Left"  Grid.Row="1" Grid.Column="1"  Background="White" Margin="12,23,0,0"
     VerticalAlignment="Top" Width="411" Height="175" Loaded="filesReceivedList_Loaded">

        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel Width="404" Height="19" Orientation="Horizontal" >
                    <TextBlock x:Name="ListFileName" Text="{Binding FileName}" Width="283"  VerticalAlignment="Center">
                        <ToolTipService.ToolTip>
                            <ToolTip Content="{Binding FileName}"></ToolTip>
                        </ToolTipService.ToolTip>
                    </TextBlock>
                    <TextBlock Text="{Binding fileCopies}" Width="50"  VerticalAlignment="Center"/>
                    <TextBlock Text="{Binding FileID}" Width="0" Visibility="Collapsed"  VerticalAlignment="Center"/>

                    <Image Source="images/Edit.png" MouseLeftButtonUp="Image_MouseLeftButtonUp_1" Width="20" Margin="0 0 0 0">
                        <ToolTipService.ToolTip>
                            <ToolTip Content="Edit"></ToolTip>
                        </ToolTipService.ToolTip>
                    </Image>

                    <TextBlock Text="" Width="10" />

                    <Image Source="images/Delete.png" MouseLeftButtonUp="Image_MouseLeftButtonUp" >
                        <ToolTipService.ToolTip>
                            <ToolTip Content="Delete"></ToolTip>
                        </ToolTipService.ToolTip>
                    </Image>
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

Let me know if any important pieces of code are missing. I'm not sure how the data source works exactly.

4

1 回答 1

0

我最终让它工作了。很简单。我只是没有在ahwile中使用过SL。这就是我所做的,尽管有人可能会提供更好的方法作为更好的答案:

    void detailsWnd_Closed(object sender, EventArgs e)
    {
        changeFileCopies(detailsDlg.FileName, detailsDlg.nCopies.Text);
    }

    public void changeFileCopies(string filename, string newCopies)
    {
        var row = (FileReceivedItem)filesReceivedDataSource.Where(x => x.FileName == filename).FirstOrDefault();
        row.fileCopies = newCopies;
        filesReceivedList.ItemsSource = null;
        this.filesReceivedList.ItemsSource = filesReceivedDataSource;
    }
于 2012-10-26T00:18:28.370 回答