|
How else would you reload the contacts when a search value is entered?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
It is mostly done in the SearchCommand... Which is triggered if the user hits the enter key or if a small amount of grace period has passed.
|
|
|
|
|
That seems like a lot of work - hook up a command to a property to fire a method??
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
It just sound like a lot of work, but it isnt.
If you have fire and forget async methods in the property, you can't control what they are doing. You don't know if there are started or finished or whatever... If you have somewhere code that depends on the result of your fire and forget code, then you will looking for bugs that you will never find.
If your fire and forget code is just updating visual stuff (like icons or colors...) then well go for it... If other logic depends on it... Don't do it. Well actually you can do it, if you a fan of bugs. Debugging is a fun hobby. More fun if you are debugging asyncronous code.
On top of that... Fire and forget code is very hard (most of the time impossible) to unit test.
|
|
|
|
|
Kevin Marois wrote: I've read that it's not a good idea to fire an sync method from a property
Did you mean "async method", not "sync"?
|
|
|
|
|
Yes
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Any searching I do, usually incrementally on a separate thread, gets invoked from the "text changed" event of the target textbox. Keyed input get queued or discarded depending on what the "search" is doing at any given time. The search might involve a web service (e.g. postal addresses).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Hi everybody,
I have implemented a Icommand RowHeaderToggleButton in my MVVM application type.
My problem: whenever I click on the toggle button, nothing happens.
Could someone help me with this issue?
Best regards,
Hervend
xaml:
<datagrid.rowheadertemplate>
<datatemplate>
<togglebutton x:name="RowHeaderToggleButton" cursor="Hand"
="" command="{Binding RowHeaderToggleButtonCommand}">
c# (inside view model):
public AlarmsListViewModel(DataBase dataBase)
{
this.dataBase = dataBase;
this.alarms = new ObservableCollection<alarmviewmodel>();
foreach (Alarm alarm in this.dataBase.Alarms)
{
this.alarms.Add(new AlarmViewModel(alarm));
}
this.ListOfAlarms = CollectionViewSource.GetDefaultView(this.alarms);
if (this.ListOfAlarms == null)
throw new NullReferenceException("ListOfAlarms");
this.ListOfAlarms.CurrentChanged += new EventHandler(this.OnCollectionViewCurrentChanged);
}
#region Fields
private readonly DataBase dataBase;
private readonly ObservableCollection<alarmviewmodel> alarms;
private readonly ICollectionView ListOfAlarms;
private ICommand rowHeaderToggleButton;
#endregion //Fields
...
public ICommand RowHeaderToggleButtonCommand
{
get
{
if (this.rowHeaderToggleButton == null)
this.rowHeaderToggleButton = new RelayCommand(() => this.RowHeaderToggleButton_Click(), () => this.CanToggle());
return this.rowHeaderToggleButton;
}
}
private bool CanToggle()
{
return true;
}
private void RowHeaderToggleButton_Click()
{
DataGridRow row = this.ListOfAlarms.CurrentItem as DataGridRow;
if (row.DetailsVisibility == Visibility.Visible)
row.IsSelected = false;
else
row.IsSelected = true;
}
|
|
|
|
|
Where do you bind the DataTemplate to the class? I.e something like:
<DataTemplate DataType="{x:Type local:AlarmsListViewModel}">
|
|
|
|
|
Hi Kenneth,
Thank you for your reply. Actually for me the DataTemplate concept seems a little bit hard to handle when dealing with some types of objects. And, in this specific case, a simple toggle button in the MVVM approach.
The range of the DataTemplate is limited to the toggle buttons associated to the rows of the DataGrid. that's the reason why I didn't have added extra arguments to it. But as I already stated, I'm still struggling to understand the way of correctly applying the DataTemplating.
|
|
|
|
|
Hervend wrote: the toggle buttons associated to the rows of the DataGrid
Ah, I didn't notice that bit. The problem is that the RowHeaderTemplate does not inherit the DataContext (ItemsSource) set on the DataGrid: DataGrid.RowHeaderTemplate Property (System.Windows.Controls)[^]
So it is recommended to use a Style instead (you might have to change the syntax as Im typing from the top of my head):
<DataGrid.RowHeaderTemplate>
<DataTemplate>
<ToggleButton x:Name="RowHeaderToggleButton" Cursor="Hand"/>
</DataTemplate>
</DataGrid.RowHeaderTemplate>
<DataGrid.RowHeaderStyle>
<Style>
<Setter Property="Button.Command" Value="{Bidning RowHeaderToggleButtonCommand"/>
</Style>
</DataGrid.RowHeaderStyle>
|
|
|
|
|
Hi
How to get notification/alert window,while working in application C#
I want to get meeting schedule alert(particular logged in user if he has meeting) every one hour before the meeting.
I am getting data from database.
The process is executed using 'exe' application using windows services
but I do not know to execute windows services and call the 'exe' application and make alert window
Can you please help me to find the solution
Thanks and Regards
Ramachandran
|
|
|
|
|
The problem is that if this is a service app, it can;t have any user interface, or interact directly with the user in any way - in fact there doesn't even have to be a user logged in to interact with when a service is running. Nor can a service app start a non-service app which does have a user interface. So you can't do what you want without having a user application running which the service can communicate with to handle the user display.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
If your question is about an app running on a server "pushing" notifications to users running your client-side app, start here: [^]
If your question is about client-side apps that read some time-stamped data from a server, then need to trigger a notification, consider a SystemTray app: [^]
If you clarify your question further, that will benefit all of us,
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
You can create a Windows app that gets started at Windows startup, runs hidden or as as icon in the taskbar, queries the db on a timer, and "shows" when there is an announcement.
"Closing" the window only hides it, and shows itself again with new announcements.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
I'm working on a program that needs to model polynomials. The program has a Number class, and an Integer class that derives from it. There is some polynomial behavior that applies to polynomials with any Number coefficients, and some, like getPsuedoRemainder(), that applies only to Integer coefficient polynomials. This seemed to me like a natural application of class inheritance. I tried a structure like this,
class Polynomial<T> where T : Number
{
List<T> Coefficients { get; }
public Polynomial(List<T> coefficients)
{
Coefficients = coefficients;
}
}
class IntegerPolynomial : Polynomial<Integer>
{
public IntegerPolynomial(List<Integer> coefficients) : base(coefficients)
{ }
}
with the operations that apply to both classes, like addition and multiplication, defined in Polynomial<t>* and the Integer-specific ones defined in IntegerPolynomial. However, I ran into trouble choosing appropriate return types for the operations defined in Polynomial<t>. For example, the sum of two Polynomial<number> objects needs to be either another Polynomial<number> object or something that is castable to one, and likewise for IntegerPolynomial objects. This is the case because I need to be able to, for example, add two IntegerPolynomials and call getPsuedoRemainder() on the result. In order for the Polynomial<number> case to work out correctly, as far as I can tell that leaves me the choice between the following two signatures:
public static Polynomial<T> operator +(Polynomial<T> a, Polynomial<T> b)
public static Polynomial<Number> operator +(Polynomial<T> a, Polynomial<T> b)
The latter obviously doesn't also make sense for the IntegerPolynomial case. The former almost does, in that it would return Polynomial<integer> objects, but I've found that it isn't legal to cast from Polynomial<integer> to IntegerPolynomial.
Is there a way to tweak this structure so that the types work out? Or is there a much different structure that would be more appropriate?
*The preview shows every type I have in angled brackets inline in paragraphs as lower-case even though I typed them all as upper-case, as in the code examples. If you see the discrepancy, note that it isn't meaningful.
modified 6-Jan-18 4:19am.
|
|
|
|
|
If IntegerPolynomial overloads the operator+ too, then the problem of them adding to a "less useful type" is solved. It can pass-through the implementation, it just has to convert back to an IntegerPolynomial in the end.
Which leads me to: you can cast them, just not by a "free" type change. A Polynomial<Integer> isn't an IntegerPolynomial so you can't take an instance of it and change the type, but you can add a conversion operator to IntegerPolynomial so that it can be created out of a Polynomial<Integer> (creating a new instance with the same contents). Though this requires that Polynomial<Integer> is not the base class of IntegerPolynomial, so it's a bit annoying. Basically it trades being able to convert "for free" and code-sharing for the ability to convert in any direction.
|
|
|
|
|
"It can pass-through the implementation, it just has to convert back to an IntegerPolynomial in the end." Having the IntegerPolynomial version call the Polynomial<t> version, then convert the result, right?
"Though this requires that Polynomial<integer> is not the base class of IntegerPolynomial, so it's a bit annoying." I had previously encountered the idea that it isn't legal to define a cast from a base class to a derived class - is that what you're referring to here? I'm not sure how or if I could have Polynomial<integer> not be the base class of IntegerPolynomial and still get the code reuse I want, but maybe I could define a method, rather than a cast, that does this conversion:
public IntegerPolynomial getIntegerPolynomial()
{
List<Integer> coefficients = new List<Integer>();
foreach (Number coefficient in Coefficients)
coefficients.Add((Integer)coefficient);
return new IntegerPolynomial(coefficients);
}
It's kind of gross because I would only ever call it from Polynomial<integer> objects, where the creation of a new List is redundant, but the conversion is necessary for it to count as valid code. Seems like it would work in a pinch though.
modified 6-Jan-18 5:21am.
|
|
|
|
|
Yes I don't really like it either.. Here's an other idea: abandon a class for integer polynomials, and just add new methods to the generic polynomial through extension methods. Unlike normal methods, extension methods get to choose a specific instantiation of a generic type to "belong to", like this:
static Polynomial<Integer> Foo(this Polynomial<Integer> x)
{
}
Which has its own set of problems, such as that extension methods have no access to private fields/methods.
|
|
|
|
|
I was completely unaware of this option. It might work like a charm.
|
|
|
|
|
It did indeed, and saved me from doing a zillion casts I thought I was going to have to do.
|
|
|
|
|
Alexander Kindel wrote: There is some polynomial behavior that applies to polynomials with any Number coefficients, and some, like getPsuedoRemainder(), that applies only to Integer coefficient polynomials
That description doesn't sound like inheritance at all.
Any time one attempts to push behavior, and only behavior into an inheritance hierarchy then one must realize that they are doing so not because it is represented of inheritance but rather because it is convenient.
And doing that a lot will likely lead to maintenance problems over time.
|
|
|
|
|
By all means let me know what the principled thing to do instead would be, though I do have a solution that seems to be working fine for the moment in the form of harold aptroot's extension method suggestion.
|
|
|
|
|
Depends on specifics but in general one looks to composition or helper classes. Or even taking a look at the architecture to see if the overall design is flawed.
|
|
|
|
|
I created a button, and then in its mouse click event handler (the button_Click method) I have actions to perform once the user clicks on that button.
The next day, I would like to modify the button_Click method, I find that this method is empty, it does not contain any code !!!! Bearing that the button works well and the actions are done as usual !!!
The event clicks on the button is related to the button_Click method, but this method is empty !! So I want to know how the actions are performed once I click onthe button ?
Thank you
|
|
|
|