Saturday, August 31, 2013

how to access an XAML control from code



I of course changed the code because I want to experiment and learn, I get this problem that the WaypointList listview doesn't update when I try to edit one of the items. the adding and deleting part works perfectly.


basically what I did is create a class that will hold the data and then add waypoints using the class.


here is the code for only the edit part and the XAML. if needed other parts please let me know.


Thank you


XAML


--------------



<ListView x:Name="WaypointList" ManipulationDelta="ListViewManipulationDelta" Background="#33309501" BorderBrush="#FF309501"
BorderThickness="2" ManipulationMode="All" Visibility="Collapsed" Header="Route addresses" HorizontalAlignment="Right"
VerticalAlignment="Center">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Width="Auto">
<TextBlock Text="{Binding Path=ViaType}" FontWeight="Bold" Margin="10,0,0,0" FontSize="18" Foreground="Black" />
<TextBlock Text="{Binding Path=SimpleAddress}" Margin="20,0,0,0" FontWeight="Bold" FontSize="18" Foreground="Black" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.RenderTransform>
<TranslateTransform />
</ListView.RenderTransform>
</ListView>

here is the edit part


-------------------------



private void Edit_Click(object sender, RoutedEventArgs e)
{
var selectedIndex = WaypointList.SelectedIndex;
NewItem.Text = WayPoints[selectedIndex].SimpleAddress;
DialogButton.Content = "Change";
EntryDialog.IsOpen = true;

NewItem.Focus(FocusState.Programmatic);

}

here is how I instantiate the class



ObservableCollection<Viapoints> WayPoints;

public MainPage()
{
this.InitializeComponent();
WayPoints = new ObservableCollection<Viapoints>();
WaypointList.ItemsSource = WayPoints;

}


the edit is actually happening in the class but not in the listview


I hope it has some sense.


thank you



No comments:

Post a Comment