|
Hi SelvaKathir,
I assume you have implemented the following things for triggering the Error.
1. Viewmodel implements IDataErrorInfo interface.
2. Set ValidationAttribute on each property which has to be validated or Use SelfValidation attribute on the class and override DoValidate.
3. Controls in Xaml are using bindings and ValidatesOnDataErrors=true,NotifyOnValidationError=true
4. Use a textblock to display the error by binding the error content of the target field. "<TextBlock Text="{Binding Validation.Errors)[0].ErrorContent, ElementName=YourTargetTextBox />"
5. Now how to display the error content on Save?
You have to set a boolean flag in ViewModel such as CanErrorDisplay and set it to true on Save.
6. Override the ErrorTemplate style and put conditional trigger on CanErrorDisplay and Validation.HasError to display Error.
This should work as per your requirement.
|
|
|
|
|
Hi All,
Am new to usage of WPF.Installed latest WPF toolkit and tried to make a window in Visual Studio 2008.
I am not able to drag and drop other WPF controls after the first drag and drop.
Explaining further, for ex. I have dropped a Label control onto window1.xaml and have configured it accordingly.
Next, I want another label or textbox or even grid on the window.But to my surprise,I was not able to drag and drop any other control.On one of the Microsoft forums, they told to delete the .tbd files from the AppData directory and reset the toolbox.Did all these stuffs but no success as of yet.
Please assist.
Anurag
A Curious Newbie...
|
|
|
|
|
Go to the Visual Studio command prompt and try to reset the environment by using devenv /resetsettings .
You will however loose all VS settings that you may have created as customized settings.
|
|
|
|
|
hii..got around the problem by upgrading the .net framework 3.5 to SP1..now i am able to drag and drop other controls...however, a new problem persists..I am not able to customize the toolbox though..i right clicked on the toolbox area and clicked on choose items..then a dialog box appears with various menus..clicked on 'WPF components'..chose the controls which i needed and then clicked on OK..but to my surprise the controls were not added...tried it again 2-3 times but to no success..restarted VS again and repeated the whole procedure but couldn't do it...Please help..
Anurag
A curious newbie
|
|
|
|
|
Please let me be more percise with the problems that are occuring. What I have are two list boxes and add/remove buttons between them. Now what I do is have a collect for the ALL ITEMS and a collection for the SELECTED ITEMS. What is happening is that when the user selects an item from the ALL ITEMS list and clicks the add button it does not show up in the SELECTED ITEMS list until the user clicks the add button one more time. What I am doing is iterating through the allItems collection and checking for the item in the selectedItems list. Now, if the item that was selected during the add button click event is not in the selectedItems list the I use the .Add method to add it to the SELECTED ITEMS list box. After the first item makes it over to the SELECTED ITEMS then the Add/Remove buttons work just fine. What we did to test this and determine that it was a Silverlight 5.1 client issue is switch out, starting at version 4.0 then 5.0 then finally 5.1 clients and everything worked fine for 4.0 and 5.0 but when 5.1 was loaded on the client it start to experence the problem. If anyone can provide some insite that would be great!
Thanks,
Steve Holdorf
|
|
|
|
|
Can you post your code && XAML please..I don't think Silverlight client has to do anything with your issue.
Cheers!
Vinod
Vinod Kumar Prajapati
Software Engineer
EBC Publishing Pvt. Ltd.
|
|
|
|
|
Hi, I'd like to do a simple game with a little amount of user interation (mouse and keypad) and I really don't know which can be the best approach for the implementation, considering the issue of animations that hav to be implemented.
Wpf could be the "correct" option or also html5+javascript can be ok ?
Thanks.
Best regards, Stefano.
|
|
|
|
|
Use WPF for a desktop application.
Web browser - use Silverlight or html5 (based on what you are comfortable with).
|
|
|
|
|
Hi friends,
I have Observable collection list of prefix which is binded with the combobox itemsource prperty in VIEW.
SelectedPrefix Property which is binded with selectedValue property.
Now when I change the List and remove some items the SelectedPrefix is not updated.
For Example I have selected Dr in combobox. The SelectedPrefix is also updated with Dr
Now if I remove the Dr from the List SelectedPrefix still contain Dr. it should be null or empty.
WANTED wasim khan(Killed 50 Innocent Buggs, Distroyed 200 Exception, make 5 Project Hostage) any Compnay Hire him will pay 30,000. Best place where u can get him is Sorcim Technologies Murre Road RWP
|
|
|
|
|
Are you using INotifyPropertyChanged in your collection?
|
|
|
|
|
I have an annoying problem with the WPF TreeView. I'll try to explain it.
The TreeView is populated with a root item which contains of 47 sub nodes. The scrollbar is automatically displayed since all sub nodes cannot fit into area where the TreeView is located in.
When I right click, to display a context menu, on a sub node while the scrollbar is at the top position; the correct sub node is selected and I can add sub nodes for that sub node.
But when I right click on a sub node which is only displayed when the scrollbar is moved down, either a bit or to the bottom, the problem occurs.
This cause the scrollbar to automatic jump back up to the top. The sub node which I right clicked on is not selected. The lowest displayed sub node, when the scrollbar is at the top, is instead selected.
I'll try to illustrate this with ASCII art
RootItem
SubNode1
SubNode2
SubNode3
SubNode4
SubNode5 <- This node is selected
--- Border which enables scrollbar
SubNode6
SubNode7
SubNode8
SubNode9 <- Right click here Ascii art FTW!
Notice the "border"-line which indicates that only Subnode1 to SubNode5 is displayed when the scrollbar is at the top. SubNode6 to SubNode9 are only displayed when the scrollbar is at the bottom.
When right clicking on "SubNode9" the SubNode5" is selected.
I wish could display the source code but my boss forbids me to include the entire code section of the TreeView. Also the code is complicated to understand by just pasting clips of it into this post.
Any suggestions what could case this? I can include code if you ask for a section of it.
/Steffe - Today I have Age++
|
|
|
|
|
In these cases, sometimes it's enough just to increase the height of the control a bit.
Any item in a "list / items" type of control that is not completely visible when it is clicked will generally cause scrolling.
|
|
|
|
|
Hi all
I want to set webcam brightness and contrast in silverlight.after hours googleing i found ShaderEffectLibrary.but it adjust the preview brightness and contrast and when i capture image from webcam,it's image is in default brightness and contrast.here is part of my code :
capture.Start();
previewWindow.Background = capture.Brush;
ContrastAdjustEffect effect = new ContrastAdjustEffect();
effect.Brightness = 1.2;
effect.Contrast = 1.2;
previewWindow.Effect = effect;
can any one help me!sorry for my poor english
|
|
|
|
|
Hi
I have a class called ErrorStatus. I am trying to use this class as a property in my interface. When a method is called and an error is thrown I want to populate this object.
I then call the methods of this interface from my viewmodel. I want to bind to properties of ErrorStatus from my xaml, through my viewmodel to the ErrorStatus property of the interface, but it doesn't seem to be working.
The error text isn't being displayed and the HasError isn't being retrieved. I suspect this is something to do with INotifyPropertyChanged and the scope.
I have cut the code down to the essentials.
I have the following class, ErrorStatus:
public class ErrorStatus : INotifyPropertyChanged
{
#region Properties
bool _hasError = false;
public bool HasError
{
get { return _hasError; }
set
{
_hasError = value;
this.RaisePropertyChanged("HasError");
}
}
string _text = String.Empty;
public string Text
{
get { return _text; }
set
{
_text = value;
if (value != String.Empty)
HasError = true;
this.RaisePropertyChanged("Text");
}
}
#endregion
public void Add(String error)
{
Text = error;
}
#region INotifyPropertyChanged Interface
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void RaisePropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
}
I also have the interface, IService:
public interface IService : INotifyPropertyChanged
{
#region Properties
ErrorStatus ServiceStatus{get;}
#endregion
void TestMethod();
}
and the implementation, Service:
public class MyService : IService
{
private ErrorStatus _serviceStatus = new ErrorStatus();
public ErrorStatus ServiceStatus
{
get { return _serviceStatus; }
private set
{
if (_serviceStatus!= value)
{
_serviceStatus= value;
RaisePropertyChanged("ServiceStatus");
}
}
}
public void TestMethod()
{
ServiceStatus.Add("TEST MESSAGE");
}
#region INotifyPropertyChanged Interface
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void RaisePropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
}
Any help would be much appreciated, thanks.
|
|
|
|
|
What does your XAML look like? Assuming you are binding to MyService, I'd expect to see references to ServiceStatus.HasErrors , etc, in there.
|
|
|
|
|
Hi Pete
In my ViewModelBase I have an instance of the interface, called MyService.
So then in my actual ViewModel I have the property, ErrorStatus which is what I am binding to in XAML:
private ErrorStatus _errorStatus;
public ErrorStatus ErrorStatus
{
get { return _errorStatus; }
set
{
if (_errorStatus != value)
{
_errorStatus = value;
RaisePropertyChanged("ErrorStatus");
}
}
}
I am also creating an event handler in my viewmodel for property changes in the interface.
MyService.PropertyChanged += MyService_PropertyChanged;
private void MyService_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case "ServiceStatus":
ErrorStatus = MyService.ServiceStatus;
break;
}
}
Would this be the correct approach or should I just create a public property for the viewmodelbase interface instance and bind to the properties through that?
modified 29-May-12 8:52am.
|
|
|
|
|
Does your XAML look like this?
<TextBlock Text="{Binding ErrorStatus.Text}" />
|
|
|
|
|
|
I've just tried your sample and it works perfectly for me (OK, I cheated in doing a little bit of code behind to add the DataContext, but the principal is still valid). My code-behind looks like this:
private MyService status = new MyService();
public MainWindow()
{
InitializeComponent();
this.DataContext = status;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
status.TestMethod();
} The XAML looks like this:
<Window
x:Class="ErrorStatusTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:vm="clr-namespace:ErrorStatusTest"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="525"
Height="350"
Title="MainWindow">
<Grid>
<TextBlock
HorizontalAlignment="Left"
Margin="116,93,0,0"
VerticalAlignment="Top"
Text="{Binding ServiceStatus.Text}"/>
<Button
Width="75"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Click="Button_Click"
Content="Button"/>
</Grid>
</Window>
|
|
|
|
|
Ah right ok, so you are binding to the service properties directly. If you saw in my previous post I have a property in my viewmodel and have a property changed event handler for when a property in the service changes. I was then setting the viewmodel property here.
Is it completely acceptable to declare a public property in my viewmodel for the interface instance in my viewmodelbase and bind to this directly?
So my ViewModelBase has this:
protected IService MyService
{
get { return GetService<IService>(); }
}
And in my ViewModel I would do this and bind to it directly from the XAML?:
public IService Service{get{return MyService;}}
|
|
|
|
|
Right. Got it.
OK, you've got quite a complicated little setup going on here, but the problem lies in the fact that you ultimately aren't propagating the change notification back up the chain here. Basically, your property changed bit in your previous sample only sets the ErrorStatus if the objects are different (which they aren't going to be), so the change notification doesn't reach the XAML (effectively, you've swallowed the change notification).
If I were you, I would look at using a property observer instead - Josh Smith details how to do this here[^].
|
|
|
|
|
Thanks Pete, yes I thought it was probably something like that.
How about the alternative of a public property for the interface instance?
I'll also take a look at the link you posted.
|
|
|
|
|
UCLAdam wrote: How about the alternative of a public property for the interface instance?
You could do that (this, in effect, is what the flattened version I used did). I prefer the property observer though.
|
|
|
|
|
Yes pretty much.
I've had a look at the post, looks interesting. Would you be able to give me pointers to how this would work in my sample?
Obviously I have the PropertyObserver class now. In my viewmodel would I do something like:
PropertyObserver<IService> _observer = new PropertyObserver<IService>(MyService).RegisterHandler(w => w.ErrorStatus, w=> ErrorChanged(w.ErrorStatus));
private object ErrorChanged(ErrorStatus errorStatus)
{
throw new NotImplementedException();
}
|
|
|
|
|
That looks about right to me.
|
|
|
|