|
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
|
|
|
|
|
There is some kind of action that results in the IDE making a duplicate method that is renamed with a "-1" at the end or something like that. You may have run into something where you inadvertently created a duplicate method and wrote the working code there. And then when you look at the method in your code it looks empty. That is because it is the other method where you wrote the code that is actually running. That has happened to me several times and it can be quite frustrating. Good Luck!
|
|
|
|
|
Go to the design view, highlight your button, and look at the Properties pane. Select "Events" - it's looks like a lightning bolt - and scroll down to Click.
Look at the method that is attached, and note what it is called.
Now open the drop down and look at the list of compatible methods.
Are there two with similar names?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
A possibility: you have modified the Button Click EventHandler, but, somehow, whatever Project/Class contains your code has not been re-compiled.
What's the structure of your app: single project ? WinForms? Or ?
Unfortunately, this is not just speculation: it happens to me now using VS2017 WinForms when I am using multi-project solutions, multiple namespaces, etc.
For unknown reasons I have to rebuild every part of the solution ... sometimes more than once ... to have the changed code used at run-time.
«... 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
|
|
|
|
|
That's usually a result of a glitch in the matrix: did you take the blue pill or the red pill this morning?
Also: clean your solution, close VS.
Manually check the file modification timestamps: just sorting in descending order should do.
Reopen VS, clean again, and rebuild all.
This has fixed it for me when I've had this problem before with 2010, 2013, and 2015 VS
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hi Griff,
I took the green pill, the one with the creme de mental flavour ... from that hookah-puffing caterpiggle's VSOPR stock
I am already following your kind advice when I get so tired of repeating the clean-rebuild-build cycle that I'm desperate enough.
Sometimes I will remove references to the class project dll's used in a WinForm project, and then re-add them. Even though I have cleaned and built the code in the classes with no output warnings ... the main solution won't build and can show a variety of error type feedback.
For me these problems started with VS2015, and hav gotten worse in VS 2017 ... that may reflect a change in my programming practice to breaking out functional units with no UI into separate class projects ... for future re-use.
cheers, Bill
«... 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
|
|
|
|