Friday, August 30, 2013

how to access an XAML control from code

Ok I got it fixed thanks to you. here is what I found


http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-2


I implemented the INotifyPropertyChanged


working perfect now.


sweet


how to access an XAML control from code

here is the class with the changes



public class Viapoints : INotifyPropertyChanged

{
private string _simpleAddress;
private string civicNumber;
private string civicName;
private string civicCity;
private string civicPostalCode;
private string civicProvince;
private string viaType;


public Viapoints()
{


}

public Viapoints(string simpleAddress, string viatype)
{
this._simpleAddress = simpleAddress;
this.ViaType = viatype;


}
public Viapoints(string cnumber, string cname, string ccity,string cpostalcode, string cprovince)
{
this.civicNumber = cnumber;
this.civicName = cname;
this.civicCity = ccity;
this.civicPostalCode = cpostalcode;
this.civicProvince = cprovince;
}

public string SimpleAddress
{
get { return _simpleAddress; }
set { _simpleAddress = value;
NotifyPropertyChanged();
}

}
public string ViaType
{
get { return viaType; }
set { viaType = value; }

}
public string CivicNumber
{
get { return civicNumber; }
set { civicNumber = value; }
}

public string CivicName
{
get { return civicName; }
set { civicName = value; }
}

public string CivicCity
{
get { return civicCity; }
set { civicCity = value; }
}

public string CivicPostalCode
{
get { return civicPostalCode; }
set { civicPostalCode = value; }
}

public string CivicProvince
{
get { return civicProvince; }
set { civicProvince = value; }
}

public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}


}


Using a JavaScript Array as a Table valued Parameter for SQL Server Stored Procedure

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



I have two XML documents, identical in structure. If a element value in A is different than B, then it needs to be copied to B (or a copy of B).

Hi,


I have two XML documents, identical in structure. If a element value in A is different than B, then it needs to be copied to B (or a copy of B).


The solution can be using either xmlDocument or XDocument, I'm not particular as long as it works. I'm using **framework 4.0**, so I guess XDocument is the more modern approach.


So it seems logical to me that I would traverse every node/element of document A, and then query the same in B and compare values, and if different, then the A element value gets copied to the same element in B (or a copy of B).


I'm a total newbie with querying XML documents in **C#**, so I thought I'd ask here to save time.


Thanks,


Barry




Barry O'Neill


I have two XML documents, identical in structure. If a element value in A is different than B, then it needs to be copied to B (or a copy of B).

Hi,


You can use the SelectNodes method of XMLDocument to select the particular node then you can modify the value for that.


Please check the below URL


http://social.msdn.microsoft.com/Forums/vstudio/en-US/d512b5d3-a98d-4970-a26b-15d07fd41e4b/get-xml-node-value-using-xpath-c


Best Regards


Muthuraja


I have two XML documents, identical in structure. If a element value in A is different than B, then it needs to be copied to B (or a copy of B).

UPDATE FOR CLARIFICATION: The element values in A will either be the string "No Change" or something else, indicating a value that needs to be updated in B. That is why I can't just copy the entire document over. If there is "No Change" for an element I don't touch whatever value is already there for the same element in B. If there is anything other than "No Change" then that value gets copied to B. In other words, B's values remain unless there is an updated one in A.


Barry O'Neill