Click here to Skip to main content
16,010,553 members
Home / Discussions / C#
   

C#

 
GeneralRe: creating a pause? Pin
Ravi Bhavnani24-Sep-10 10:12
professionalRavi Bhavnani24-Sep-10 10:12 
GeneralRe: creating a pause? Pin
AspDotNetDev24-Sep-10 10:35
protectorAspDotNetDev24-Sep-10 10:35 
QuestionText Pin
SatyaKeerthi1524-Sep-10 2:37
SatyaKeerthi1524-Sep-10 2:37 
AnswerRe: Text Pin
Henry Minute24-Sep-10 2:44
Henry Minute24-Sep-10 2:44 
AnswerRe: Text Pin
Saksida Bojan24-Sep-10 6:23
Saksida Bojan24-Sep-10 6:23 
QuestionTextbox Text Pin
SatyaKeerthi1524-Sep-10 2:35
SatyaKeerthi1524-Sep-10 2:35 
AnswerRe: Textbox Text Pin
Henry Minute24-Sep-10 2:55
Henry Minute24-Sep-10 2:55 
QuestionExam 70-511 Pin
V.23-Sep-10 22:03
professionalV.23-Sep-10 22:03 
I'm taking this exam in a little more then a week from now and am searching for some practice questions. I found some and didn't always understand the question so I tried it out. "It didn't work". Really, the code they gave as the answer did not what the question requested.

I'm curious if the source is trustworthy or if I'm going bananas here (or both Smile | :) ) ??

thanks.


below an example of such a question and expected answer:
(apologies for the formatting)

You use Microsoft .NET Framework 4 to create a Windows Presentation Foundation (WPF) application.
You write the following code fragment.
<StackPanel TextBox.PreviewTextInput="StackPanel_PreviewTextInput">
<TextBox Name="TxtBoxA"/>
<TextBox Name="TxtBoxB"/>
<TextBox Name="TxtBoxC"/>
</StackPanel>
You create an event handler named StackPanel_PreviewTextInput. You also have a collection of strings named Keywords.
You need to ensure that TxtBoxA and TxtBoxB do not contain any of the strings in the Keywords collections.
Which code segment should you use?

A. private void StackPanel_PreviewTextInput(
object sender, TextCompositionEventArgs e)
{ FrameworkElement feSource = sender as FrameworkElement;
if (feSource.Name == "TxtBoxA" || feSource.Name == "TxtBoxB")
{ foreach(string keyword in Keywords)
{
if(e.Text.Contains(keyword)) { e.Handled = false;
return;
}
}} e.Handled = true;
} }

B. private void StackPanel_PreviewTextInput(
object sender, TextCompositionEventArgs e) {
FrameworkElement feSource = e.Source as FrameworkElement;
f (feSource.Name == "TxtBoxA" || feSource.Name == "TxtBoxB")
f (feSource.Name == "TxtBoxA" || feSource.Name == "TxtBoxB") {
foreach(string keyword in Keywords)
{
if(e.Text.Contains(keyword)) { e.Handled = false;
return;
}
} e.Handled = true;

C. private void StackPanel_PreviewTextInput(
object sender, TextCompositionEventArgs e)
{
FrameworkElement feSource = sender as FrameworkElement;
if (feSource.Name == "TxtBoxA" || feSource.Name == "TxtBoxB")
{ foreach(string keyword in Keywords)
{ if(e.Text.Contains(keyword)) {
e.Handled = true;
return; }
} e.Handled = false;
} }

D. private void StackPanel_PreviewTextInput(
object sender, TextCompositionEventArgs e)
{ FrameworkElement feSource = e.Source as FrameworkElement;
if (feSource.Name == "TxtBoxA" || feSource.Name == "TxtBoxB")
{
foreach(string keyword in Keywords)
{ if(e.Text.Contains(keyword)) {
e.Handled = true;
return;
} } e.Handled = false;
}
}


Answer D is the right answer...

However, following the question I found following to actually do what was requested:
(except when you paste the word in the textbox so even the idea of using this code for the requested functionality is not really ideal)

the problem was that e.Text only gave the typed character and not the entire contents.
		private void StackPanel_PreviewTextInput(object sender, TextCompositionEventArgs e){
			FrameworkElement feSource = e.Source as FrameworkElement;
			if (feSource.Name == "TxtBoxA" || feSource.Name == "TxtBoxB") {
				foreach (string keyword in Keywords) {
					lbl_info1.Content = e.Text;
//following if statement is my 'enhancement'
					if ( ((((TextBox)feSource).Text)+e.Text).Contains(keyword)) {
						e.Handled = true;
						return;
					}
				} 
				e.Handled = false;
			}
		}

V.

QuestionUrl refere is null in safari Pin
MayukhSen23-Sep-10 19:53
MayukhSen23-Sep-10 19:53 
AnswerRe: Url refere is null in safari Pin
N a v a n e e t h23-Sep-10 20:24
N a v a n e e t h23-Sep-10 20:24 
Questionbest way to pass large amount of data into an object? Pin
stephen.darling23-Sep-10 18:07
stephen.darling23-Sep-10 18:07 
AnswerRe: best way to pass large amount of data into an object? Pin
Mycroft Holmes23-Sep-10 19:53
professionalMycroft Holmes23-Sep-10 19:53 
GeneralRe: best way to pass large amount of data into an object? Pin
stephen.darling23-Sep-10 20:05
stephen.darling23-Sep-10 20:05 
GeneralRe: best way to pass large amount of data into an object? Pin
N a v a n e e t h23-Sep-10 20:19
N a v a n e e t h23-Sep-10 20:19 
GeneralRe: best way to pass large amount of data into an object? Pin
stephen.darling23-Sep-10 20:37
stephen.darling23-Sep-10 20:37 
QuestionMarshalling array of struct Pin
poda23-Sep-10 17:47
poda23-Sep-10 17:47 
AnswerRe: Marshalling array of struct [modified] Pin
Luc Pattyn23-Sep-10 18:52
sitebuilderLuc Pattyn23-Sep-10 18:52 
GeneralRe: Marshalling array of struct [modified] Pin
poda23-Sep-10 19:21
poda23-Sep-10 19:21 
GeneralRe: Marshalling array of struct Pin
Luc Pattyn24-Sep-10 1:52
sitebuilderLuc Pattyn24-Sep-10 1:52 
GeneralRe: Marshalling array of struct Pin
poda26-Sep-10 17:07
poda26-Sep-10 17:07 
GeneralRe: Marshalling array of struct Pin
Luc Pattyn26-Sep-10 17:19
sitebuilderLuc Pattyn26-Sep-10 17:19 
GeneralRe: Marshalling array of struct Pin
poda26-Sep-10 23:31
poda26-Sep-10 23:31 
GeneralRe: Marshalling array of struct Pin
Luc Pattyn27-Sep-10 0:21
sitebuilderLuc Pattyn27-Sep-10 0:21 
AnswerRe: Marshalling array of struct Pin
David Knechtges24-Sep-10 3:42
David Knechtges24-Sep-10 3:42 
GeneralRe: Marshalling array of struct Pin
poda26-Sep-10 17:08
poda26-Sep-10 17:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.