|
Thank you for the link...
However, I am trying to use the following method instead which is due to the requirements...
The problem is that I would like to call the IsEmailAllowed when I click away from the Email textbox.
As you see now, the call is in the txtEmail_PreviewTextInput and so, it returns false for each character I enter into the textbox.
Which event of the textbox can I place the code e.Handled = !IsEmailAllowed(e.Text); so it gets called after clicking away from the textbox.
Thanks
private static bool IsEmailAllowed(string text)
{
bool blnVallidEmail = false;
Regex regEMail = new Regex(@"^[a-zA-Z][\w\.-]{2,28}[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$");
if (text.Length > 0)
{
if (!regEMail.IsMatch(text))
{
MessageBox.Show("E-Mail expected", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
blnVallidEmail = !regEMail.IsMatch(text);
}
}
return blnVallidEmail;
}
private void txtEmail_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
e.Handled = !IsEmailAllowed(e.Text);
}
|
|
|
|
|
You can try putting the call into the TextBox's LostFocus event, which fires when the TextBox loses focus(funny that).
Hope this helps
...and I have extensive experience writing computer code, including OIC, BTW, BRB, IMHO, LMAO, ROFL, TTYL.....
|
|
|
|
|
|
arkiboys wrote: However, I am trying to use the following method instead which is due to the
requirements...
What requirements do you have that say you have to provide your own preview check input? What you are trying to do here is actually poor form - if the user types in that doesn't match the regular expression you throw a message box up - it's better to prevent them from putting in an invalid value than telling them they got it wrong. BTW, you are using the preview key event here and then extracting the value from the textbox. In other words, if the user types in all valid characters bar the last one, your code won't catch it because it is reacting to the values that are already in the textbox, which does not include the key you've just pressed.
If what you are trying to do is just validate the input, then you need to implement IDataErrorInfo on your ViewModel, and then add the following to your binding in the textbox:
UpdateSourceTrigger=LostFocus, ValidatesOnDataErrors=true, NotifyOnValidationError=true By handling LostFocus, the validation will only occur when you focus away from the textbox. To add the validation in, you need to add the following code:
public string Error
{
get { throw new NotImplementedException(); }
}
public string this[string columnName]
{
get
{
string result = null;
if (columnName == "Email")
{
Regex regEMail = new Regex(@"^[a-zA-Z][\w\.-]{2,28}[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$");
bool isValid = regEmail.IsMatch(Email);
if (!isValid)
{
result="You must enter an email";
}
}
return result;
}
}
|
|
|
|
|
|
|
Hi,
I got that how to bind the data to a control, my question is how to read the specific data from that listbox.itemtemplate and pass it as a request...
this is my xaml file..
<ListBox Grid.Row="1" Grid.Column="2" x:Name="lbDirectiveList" ItemsSource="{Binding}" SelectionChanged="lbDirectiveList_SelectionChanged" MaxHeight="200" SelectionMode="Single" ScrollViewer.VerticalScrollBarVisibility="Auto">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Margin="4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="25" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Path=DirectiveName, Mode=TwoWay}" Grid.Column="0" FontWeight="Bold" MinWidth="200"/>
<TextBlock Text=" - " Grid.Column="1"/>
<TextBlock Grid.Column="2" Text="{Binding Path=DirectiveDescription, Mode=TwoWay}" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
here the directive name and description is displayed in a listbox, i have to get the directive name which is present inside the listbox and pass it in a soaprequest, so could u help me how to do it..
any idea...
|
|
|
|
|
You should not be reading data from the itemtemplate.
You should be reading data from the itemssource / datacontext source collection that you have bound to your listbox.
That should be fairly easy to pass to the service.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
|
|
|
|
|
so can u tell me how can i get the data through itemsource, i have to get all the DirectiveName data from listbox.
ObservableCollection<DADirective> listdata;
DADirective SelectDirective;
public void LoadDirective()
{
listdata = new ObservableCollection<DADirective>();
SelectDirective = (DADirective)lbDirectiveList.SelectedItem;
listdata.Add(new DADirective { DirectiveName = "Filter trading account", DirectiveDescription = "Rows will Trading account value to be filtered" });
listdata.Add(new DADirective { DirectiveName = "Filter Counter party rows", DirectiveDescription = "Rows where counter party is null will be filtered" });
listdata.Add(new DADirective { DirectiveName = "Filter USD currency records", DirectiveDescription = "Filter those rows where currency is USD" });
lbDirectiveList.ItemsSource = listdata;
}
|
|
|
|
|
You don't need to do anything special to read the data out of the data context or anything. All you need to do is get the data out of listdata. That's what you've bound to, there's no magic going on under the hood, so you could use a simple foreach and iterate over the listdata collection.
|
|
|
|
|
Hi please recommend any third party api for Line Chart. which has the feature of Zooming and panning and should be allowed 200,000 points.
Please let me know
|
|
|
|
|
I dont know if the charting toolkit provided on codeplex can help you - its open source.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
|
|
|
|
|
|
I'm trying to reference my Project Model class from another project from within my UI project:
<Window x:Class="Abtech.Spares.UI.Views.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
xmlns:local="clr-namespace:Abtech.Spares.DataModel.Models;assembly=Abtech.Spares.DataModel.Models"
Title="My App"
Height="600"
Width="800">
I'm trying to reference it in
<Window.Resources>
<DataTemplate x:Key="Project" DataType="{x:Type local:ProjectModel}">
<StackPanel Orientation="Horizontal">
<Image Source="/Abtech.Spares.UI;component/Media/Graphics/Sidebar/project_16x16.png" Margin="0,0,2,0"></Image>
<TextBlock Text="{Binding ProjectName}" />
</StackPanel>
</DataTemplate>
</Window.Resources>
The compiler is highligting this line
xmlns:local="clr-namespace:Abtech.Spares.DataModel.Models;assembly=Abtech.Spares.DataModel.Models"
and telling me that the assembly is not found. The assembly is referenced in this project.
The error is
Assembly 'Abtech.Spares.DataModel.Models' was not found. Verify that you are not missing an assembly reference. Also, verify that your project and all referenced assemblies have been built.
I'm not quiet sure what to do about this.
Everything makes sense in someone's mind
modified on Wednesday, April 27, 2011 4:58 PM
|
|
|
|
|
Try cleaning your solution once.
Also try to make sure that 'Abtech.Spares.DataModel.Models' exists within the assembly that you have referenced.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
|
|
|
|
|
The data model project is in my solution and I referenced the project from the UI project, which is where this error is occuring. Other classes in the UI are using the models, so the problem cannot be a reference issue. It's just this one XAML file that doesn't like it.
Everything makes sense in someone's mind
|
|
|
|
|
|
I think you should actually READ the contents of the links you posted before spouting this all over the WPF forum ...
|
|
|
|
|
guy, again, like i said to many, "If you have no answer, move on"
Don't litter my thread.
dev
|
|
|
|
|
Calm down, there...
The namespace URLs aren't websites... They're basically just aliases, and you can create your own in your Assembly.cs:
[assembly: XmlnsDefinition("http://my.make.believe.xaml.namespace.com/something", "My.CLR.Namespace")]
The advantage is that one XML namespace can refer to multiple CLR namespaces:
[assembly: XmlnsDefinition("http://my.make.believe.xaml.namespace.com/something", "My.CLR.Namespace")]
[assembly: XmlnsDefinition("http://my.make.believe.xaml.namespace.com/something", "My.CLR.Namespace.Stuff")]
[assembly: XmlnsDefinition("http://my.make.believe.xaml.namespace.com/something", "My.CLR.Namespace.More.Stuff")]
I agree that using "http" as the prefix is kind of silly (I'm guessing there was some sort of reason for it, but not looking it up right now)... But it works.
|
|
|
|
|
I don't think there is any requirement that it be an http string. It can be pretty much anything. Http is just what people use because its easy to remember (way easier then URI syntax), and it looks cool.
|
|
|
|
|
I was actually wondering about that... I think it would have made more sense to use "ns://"... Does anyone actually memorize it anyway? If it wasn't for Intellisense, I'd be looking it up online every time.
EDIT: Hmm, after seeing Pete's link... Guess using HTTP is logical... Just being standards-compliant.
|
|
|
|
|
|
Makes a change
|
|
|
|
|
Ian Shlasko wrote: I agree that using "http" as the prefix is kind of silly (I'm guessing there was
some sort of reason for it, but not looking it up right now)... But it
works.
There is a perfectly valid reason. Remember that XAML is XML Application Markup Language; the use of the URI is in line with the convention for assigning namespaces in XML. There's an "interesting" read on XML Namespaces here[^].
|
|
|
|