Click here to Skip to main content
15,906,628 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the grid as:
C#
<DockPanel Height="280">
          <Border CornerRadius="6" BorderBrush="Gray" removed="LightGray" BorderThickness="2" >
              <ScrollViewer VerticalScrollBarVisibility="Auto">
                  <ItemsControl Height="400" Name="icTodoList" ItemsSource="{Binding Items}">
                      <ItemsControl.ItemTemplate>
                          <DataTemplate>
                              <Grid Name="ToDoList">
                                  <Grid.RowDefinitions>
                                      <RowDefinition Height="*"/>
                                      <RowDefinition Height="*"/>
                                      <RowDefinition Height="*"/>
                                      <RowDefinition Height="*"/>
                                  </Grid.RowDefinitions>
                                  <TextBlock Text="{Binding StartTime, FallbackValue=' '}" Grid.Row="0"/>
                                  <TextBlock Text="{Binding ConnectedTime, FallbackValue=' '}" Grid.Row="1"/>
                                  <TextBlock Text="{Binding DisconnectedTime, FallbackValue=' '}" Grid.Row="2"/>
                                  <TextBlock Text="{Binding DialingResult, FallbackValue=' '}" Grid.Row="3"/>
                              </Grid>
                          </DataTemplate>
                      </ItemsControl.ItemTemplate>
                  </ItemsControl>
              </ScrollViewer>
          </Border>
      </DockPanel>

By clicking a button to start a process, some contents are add to the grid, But next time new stuffs are appended after the old ones. I don't want that; I want to clean up the grid once I click the button, so the layout always show the new contents.

How?

EDIT:
I used MVVM pattern.
C#
public ObservableCollection<Calls> items = new ObservableCollection<Calls>();
   public ObservableCollection<Calls> Items
   {
       get { return items; }
       set
       {
           items = value;
           RaisePropertyChanged();
       }
   }

And in the code behind:
C#
MainViewModel _dataContext;
Calls c = new Calls();
// blah blah
 Dispatcher.BeginInvoke((Action)delegate()
        {
            if (c != null)
                _dataContext.Items.Add(c);
        });
Posted
Updated 18-Nov-14 7:24am
v2
Comments
DamithSL 18-Nov-14 12:46pm    
[no name] 18-Nov-14 13:25pm    
By the way. I use MVVM. See my updated code.

I got a simple solution.
Before adding, using one line code is enough.
C#
_dataContext.Items.Clear();
 
Share this answer
 
 
Share this answer
 
Comments
Manas Bhardwaj 18-Nov-14 15:01pm    
+5!
Maciej Los 18-Nov-14 16:02pm    
Thank you, Manas ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900