I found a problem when i use the pivot control in the Windows Phone 8 SDK.
The pivot binds to a list named Students and set a button when click it,Will new a new student object and set it to Students[2] as new value. This has lead to the overlapping problem shown in the screenshot below. Has anyone else had this problem in the WP8 SDK?
Here is the code
public MainPage()
{
InitializeComponent();
this.DataContext = this;
// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
InitiList();
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
int index = 2;
Students[index] = new Student();
Students[index].Name = "tian";
Students[index].College = "shida";
}
private ObservableCollection<Student> _students;
public ObservableCollection<Student> Students
{
get { return _students; }
set
{
_students = value;
RaisePropertyChanged("Students");
}
}
private void InitiList()
{
Students = new ObservableCollection<Student>();
Students.Add(new Student { Name="a",College="aa"});
Students.Add(new Student { Name = "b", College = "aa" });
Students.Add(new Student { Name = "c", College = "aa" });
Students.Add(new Student { Name = "d", College = "aa" });
Students.Add(new Student { Name = "e", College = "aa" });
}
Ckeck this o/p image:
You're modifying Students but RaisePropertyChanged isn't getting fired because accessing Students doesn't fire Set, which calls RaisePropertyChanged. This could be the problem, I can't test it right now.
I experience the same issue, and I fixed it by adding the items to the ObservableCollection in the constructor instead of using the Add method. It appears to be a bug with the ObservableCollection class. Try changing your code to:
private void InitiList()
{
Students = new ObservableCollection<Student>(new [] {
new Student { Name="a",College="aa"}),
new Student { Name = "b", College = "aa" }),
new Student { Name = "c", College = "aa" }),
new Student { Name = "d", College = "aa" }),
new Student { Name = "e", College = "aa" })
});
}
Related
To create a workitem I need to specify its fields but where exactly can I see all the possible "field paths" on my AzureDevOps site?
I've edited an existing workitem and added some more fields to it but I cant seem to find the needed "field path" for my JsonPatchOperation.
Any ideas? Thanks in advance!
public static WorkItem CreateWorkItem(VssConnection connection, string title, string type, string description, string tags)
{
string project = "xxx";
// Construct the object containing field values required for the new work item
JsonPatchDocument patchDocument = new JsonPatchDocument();
patchDocument.Add(
new JsonPatchOperation()
{
Operation = Operation.Add,
Path = "/fields/System.Title", <-- field path
Value = title
}
);
patchDocument.Add(
new JsonPatchOperation()
{
Operation = Operation.Add,
Path = "/fields/System.Description", <-- field path
Value = description
}
);
// Get a client
WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();
// Create the new work item
WorkItem newWorkItem = workItemTrackingClient.CreateWorkItemAsync(patchDocument, project, type).Result;
Console.WriteLine("Created work item ID {0} {1}", newWorkItem.Id, newWorkItem.Fields["System.Title"]);
return newWorkItem;
}
You can use the process template editor to see all fields in your org.
Install Process Editor to VS:
Open Fields Browser:
Check needed fields:
Another way: using the rest api.
WorkItemTrackingProcessHttpClient ProcessHttpClient = Connection.GetClient<WorkItemTrackingProcessHttpClient>();
string processName = "My New Process"; //existing process
string witName = "Task"; //existing work item type
Guid procId;
string witRefName;
GetProcAndWIT(processName, witName, out procId, out witRefName);
ShowCurrentFields(procId, witRefName);
private static void ShowCurrentFields(Guid procId, string witRefName)
{
var fields = ProcessHttpClient.GetAllWorkItemTypeFieldsAsync(procId, witRefName).Result;
Console.WriteLine("{0, -20} : {1, -40} : {2, -10} : {3, -8} : {4, -8} : {5, -8}",
"Name", "Reference Name", "Type", "Required", "ReadOnly", "Default");
foreach (var field in fields)
{
Console.WriteLine("------------------------------------------------------------------------------------------------------------");
Console.WriteLine("{0, -20} : {1, -40} : {2, -10} : {3, -8} : {4, -8} : {5, -8}",
field.Name, field.ReferenceName, field.Type, field.Required, field.ReadOnly, field.DefaultValue);
}
Console.WriteLine("------------------------------------------------------------------------------------------------------------\n\n\n\n");
}
private static void GetProcAndWIT(string processName, string witName, out Guid procId, out string witRefName)
{
procId = GetProcessGuid(processName);
if (procId == null)
{
throw new Exception("Can not find process.");
}
witRefName = GetWITrefName(procId, witName);
if (string.IsNullOrEmpty(witRefName))
{
throw new Exception("Can not find work item type.");
}
}
private static Guid GetProcessGuid(string processName)
{
Guid newProcessGuid = Guid.Empty;
var processes = ProcessHttpClient.GetListOfProcessesAsync().Result;
return (from p in processes where p.Name == processName select p.TypeId).FirstOrDefault();
}
private static string GetWITrefName(Guid procGuid, string witName)
{
var wiTypes = ProcessHttpClient.GetProcessWorkItemTypesAsync(procGuid).Result;
return (from p in wiTypes where p.Name == witName select p.ReferenceName).FirstOrDefault();
}
I am testing the Multilingual Bot downloaded from Microsoft bot framework. While doing so, some of my content are not getting translated.
Image link
You can see the following code where I have inserted few lines that asks the user if there is anything I can help ? This gets translated in to tthe language selected by the User. But, the content in CardAction() object Title 'Yes' and 'No' are not getting translated.
How to handle such translations in the middleware ?
bool translate = userLanguage != TranslationSettings.DefaultLanguage;
if (IsLanguageChangeRequested(turnContext.Activity.Text))
{
await _accessors.LanguagePreference.SetAsync(turnContext, turnContext.Activity.Text);
var reply = turnContext.Activity.CreateReply($"Your current language code is: {turnContext.Activity.Text}");
await turnContext.SendActivityAsync(reply, cancellationToken);
await _accessors.UserState.SaveChangesAsync(turnContext, false, cancellationToken);
// This content is getting partially translated.
var newRply = turnContext.Activity.CreateReply("Is there anything else I can help you with?");
newRply.SuggestedActions = new SuggestedActions()
{
Actions = new List<CardAction>()
{
// The title is not getting translated
new CardAction() { Title = "Yes", Type = ActionTypes.PostBack, Value = Spanish },
// The title is not getting translated
new CardAction() { Title = "No", Type = ActionTypes.PostBack, Value = English },
},
};
await turnContext.SendActivityAsync(newRply);
}
else
{
var reply = turnContext.Activity.CreateReply("Choose your language:");
reply.SuggestedActions = new SuggestedActions()
{
Actions = new List<CardAction>()
{
new CardAction() { Title = "Español", Type = ActionTypes.PostBack, Value = Spanish },
new CardAction() { Title = "English", Type = ActionTypes.PostBack, Value = English },
},
};
await turnContext.SendActivityAsync(reply);
}
}
Expecting that string in the CardAction() should also be translated into the language chosen by the user.
I assume you are using Microsoft Translator class that comes with the Sample. From the same sample, I implemented a new class (MultilingualCardAction) by inheriting CardAction class.
This works for me but there may be better ways as well.
public class MultilingualCardAction : CardAction
{
private readonly MicrosoftTranslator _translator;
private string _language;
public MultilingualCardAction(string language)
{
_language = language;
_translator = new MicrosoftTranslator(<<YOUR TRANSLATION KEY>>);
}
public string cardTitle
{
get
{
return this.Title;
}
set
{
this.Title = getTranslatedText(value).Result;
}
}
async Task<string> getTranslatedText(string title)
{
return await _translator.TranslateAsync(title, _language);
}
}
Then I created the CardAction object this way.
var newRply = turnContext.Activity.CreateReply("Is there anything else I can help you with?");
newRply.SuggestedActions = new SuggestedActions()
{
Actions = new List<CardAction>()
{
new MultilingualCardAction('es') { cardTitle = "Yes", Type = ActionTypes.PostBack, Value = "Yes" },
new MultilingualCardAction('es') { cardTitle = "No, thanks!", Type = ActionTypes.PostBack, Value = "No" },
},
};
await turnContext.SendActivityAsync(newRply);
Refer the image below.
I am using the sample "SandwichOrder" code. When I use the property "Describe" to change the item value the bot doesn't understand the setted value.
public enum LengthOptions
{
[Describe("Test 1")]
SixInch = 1,
[Describe("Test 2")]
FootLong = 2
};
This is the output:
It's the problem how FormFlow handles the feedback after user's selection, the result is actually right the type of LengthOptions. Since we're not able to modify the source code of BotBuilder SDK, here is a workaround to solve this problem: we try to override the feedback of this item in FormFlow, and here is the code when building the FormDialog:
...
.Field(nameof(Length),
validate: async (state, response) =>
{
var result = new ValidateResult { IsValid = true, Value = response };
var value = (LengthOptions)response;
result.Feedback = "Your selection means " + value;
return result;
})
...
The Length property in above code can be defined like this:
public enum LengthOptions
{
[Describe("Test 1")]
SixInch = 1,
[Describe("Test 2")]
FootLong = 2
};
public LengthOptions? Length { get; set; }
Here is the test result:
What #Grace Feng mentioned is one way to do that. Another simpler way would be to add the Terms decoration to LengthOptions each item.
So the code would be :
public enum LengthOptions
{
[Terms(new string[] { "Test 1" })]
[Describe("Test 1")]
SixInch = 1,
[Terms(new string[] { "Test 2" })]
[Describe("Test 2")]
FootLong = 2
};
Now your bot will automatically understand the value of "Test 1" as SixInch and "Test 2" as FootLong
I have created code which adds,deletes and modify objects added to the arraylist.when i select the remove method it shows the above error.how do i solve it.This code is where i am running everything.It has an instance of the member class which has all methods neccessary
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MedicalAid
{
class MedicalTest
{
//instance of MedicalTest class
public static MedicalTest medicalMember = new MedicalTest();
//array list to hold member objects
static List<Member> customer = new List<Member>();
//instance of Member class
static Member member = new Member();
//some important booleans
private bool isSubscribed;
private bool isDeducted;
private bool isToBeRemoved;
private bool isToBeAdded = true;
//add passed memebers to arraylist
public void addMembersToArrayList()
{
customer.Add(member1);
customer.Add(member2);
isToBeAdded = false;
}
//method to add member
public void AddMember(Member name)
{
customer.Add(name);
}
//method to remove a member
public void RemoveMember(String removeName) {
foreach (Member i in customer) {
if (isToBeRemoved)
{
if (i.GetName() == removeName)
{
Console.WriteLine("Found and Removed");
customer.Remove(i);
}
else{Console.WriteLine("Not Found");}
}
if(isSubscribed)
{
if (i.GetName() == removeName)
{
//if delete member is true,delete member
Console.WriteLine("Found and Transaction Made");
i.makeSubscription();
i.showMember();
}//closes isToBeDeleted
else { Console.WriteLine("Not Found"); }
}
if(isDeducted){
if (i.GetName() == removeName)
{
//if delete member is true,delete member
Console.WriteLine("Found and Transaction Made");
i.makeSubscription();
i.showMember();
}//closes isToBeDeleted
else
{
Console.WriteLine("Not Found");
}
}//closes deducted if
}
}
//method to iterate through customer and remove a member
public void ViewMembers()
{
//iterate throus the customer list and print details of any member availabe
if(customer.Capacity == 0){
Console.WriteLine("Medical Aid List is Empty");
}else{
foreach(Member i in customer){
i.showMember();
}
}
}
//create two objects with details
Member member1 = new Member("male",
"Z.N.A",
" 272 Area 3 D/Mvura Mutare",
"Premium",
"JAMES",
500.00,
"Dr Bvirakure",
"xx-xxxxx y XX",
//spouse
"xx/xx/1987",
"JOSEPHINE MANYORE",
"XX-XXXXX-XX",
//family doctor
"DANGAMVURA SHOPPING MALL",
"0773 0733 0734",
//dependent
"male",
"ANDREW BLESSING MANYORE",
"75-426820 Y 50",
//bank details
"ZABG",
"Herbet Chitepo",
"xxxxxxxxxxxxx",
"xxxxxxxxxxxxx",
"Mutare");
Member member2 = new Member("female",
"MINISTRY OF EDUCATION",
" 272 Area 3 D/Mvura Mutare",
"Premium",
"TAPIWA",
500.00,
"Dr Bvirakure",
"xx-xxxxx y XX",
//spouse
"xx/xx/1987",
"JAMES MANYORE",
"XX-XXXXX-XX",
//family doctor
"DANGAMVURA SHOPPING MALL",
"0773 0733 0734",
//dependent
"male",
"PORTIA TATENDA MANYORE",
"75-426820 Y 50",
//bank details
"ZB",
"Herbet Chitepo",
"xxxxxxxxxxxxx",
"xxxxxxxxxxxxx",
"Mutare");
//method to print saved members
static void Main(string[] args)
{
int option;
string options;
//add the members to the arraylist
if (medicalMember.isToBeAdded)
{
medicalMember.addMembersToArrayList();
}
do{
Console.Write("********Medical Aid*********\n"+
"1.To Add New Member\n"+
"2.To Edit Member Balance if he made a Subscription\n" +
"3.To Edit Member Balance if he received a Service\n" +
"4.To Delete Old Member\n" +
"5.To View Members\n"+
"6.To Exit\n");
options = Console.ReadLine();
option = Convert.ToInt32(options);
switch(option){
case 1: member.GetMember();
medicalMember.AddMember(member);
break;
case 2 : medicalMember.isSubscribed = true;
medicalMember.isDeducted = false;
medicalMember.isToBeRemoved = false;
Console.WriteLine("Enter Member Name who made a Subscription\n");
String memberToGetSer = Console.ReadLine();
medicalMember.RemoveMember(memberToGetSer);
break;
case 3 :medicalMember.isSubscribed = false;
medicalMember.isDeducted = true;
medicalMember.isToBeRemoved = false;
Console.WriteLine("Enter Member Name who received a Service\n");
String memberToGetSub = Console.ReadLine();
medicalMember.RemoveMember(memberToGetSub);
break;
case 4: medicalMember.isSubscribed = false;
medicalMember.isDeducted = false;
medicalMember.isToBeRemoved = true;
Console.WriteLine("Enter Member Name to remove");
String memberToRemove = Console.ReadLine();
medicalMember.RemoveMember(memberToRemove);
break;
case 5: medicalMember.ViewMembers();
break;
case 6: Console.WriteLine("******EXITING********");
Environment.Exit(0);
break;
}//closes switch
}while(option<=5);//closes while
}//closes main
}//closes class
}
You can't call Remove() while inside foreach loop (as long as it concerns the collection you are looping through)
use a for loop:
for (int i=0;i<customer.Count;i++)
{
......
}
From MSDN:
The foreach statement is used to iterate through the collection to get the information that you want,
but can not be used to add or remove items from the source collection to avoid unpredictable side effects.
If you need to add or remove items from the source collection, use a for loop.
See this for more details
just change this in remove Member:
public void RemoveMember(String removeName) {
for (int i=customer.Count - 1;i>=0;i--) {
if (isToBeRemoved)
{
if (customer[i].GetName() == removeName)
{
Console.WriteLine("Found and Removed");
customer.RemoveAt(i);
}
else{Console.WriteLine("Not Found");
}
}
}
You can't remove elements if you're reading forward through a collection as the enumerator would be invalidated. Try using the RemoveAll method, it will do what you want and simplify your code:
if (isToBeRemoved) // No need for a for loop.
{
customer.RemoveAll(elem => elem.GetName() == removeName);
}
I created an arraylist of Student type. Student has name, subject information in it. Suppose my ArrayList has values like (sam, maths), (john, english), (mat, science). If i want to find out which student has science stream, then how to search it in an ArrayList.
I think it may be done by using binarysearch or indexof methods, but not getting it right.
Why did you created an arraylist of Student type ?
I'm pretty sure that you should go with a generic type-safe list : List<T>
To do your searches you could use LINQ :
List<Student> students = new List<Student>();
students.Add(new Student { Lastname = "Smith" });
students.Add(new Student { Lastname = "Foo" });
students.Add(new Student { Lastname = "SmithFoo" });
students.Add(new Student { Lastname = "SmithBar" });
var searchResults = from student in students
where student.Lastname.StartsWith("Smith")
select student;
This code will search in your students list and return three students : Smith, SmithFoo and SmithBar
Thats how I did in the end. Sorry I forgot to answer this one.
public int search(object sender, List<albums> al)
{
int i = -1;
TextBox txt = (TextBox)sender;
foreach (albums dc in al)
{
if ((dc.artist == txt) ||(dc.tag == txt))
{
i = (al.IndexOf(dc));
}
}
return i;
}