Click here to Skip to main content
14,272,574 members

Comments by Dirk Bahle (Top 37 by date)

Dirk Bahle 8-Jan-19 10:11am View
   
I only meant the INotifyPropertyChanged is necessary if you want to display the count in the UI. But thats just guess work since the provided code sample does not show what was tried so far ...
Dirk Bahle 23-Nov-18 7:50am View
   
Not sure whaz your problem is - woud you care to explain your problem?
Dirk Bahle 28-Sep-18 7:28am View
   
I have read Ben's article the other day and thought his pattern is quit interesting since I have run into similar problems. I had no time to try it out for myself but maybe there is something helpful here:
https://www.codeproject.com/Articles/1220093/A-Robust-Solution-for-FileSystemWatcher-Firing-Eve
Dirk Bahle 28-Sep-18 7:23am View
   
thanx - really funny this random downvoting...
Dirk Bahle 28-Sep-18 7:19am View
   
Thats a great start but you can still run into problems once you are looking at a large code base - what you want to do in this case is to seal your classes away into a library project and then have only the factory method and the interface definition be visible to the outside world. Copy the code below into a library project, reference the library in the startup project and use the following line to create for example a Horse: ICreature hores = Factory.CreateHorse()

    internal abstract class Creature
    {
        public virtual void Walk()
        {

        }

        public virtual void Run()
        {

        }

        public virtual void Swim()
        {

        }
    }

    public interface ICreature
    {
        void Walk();

        void Run();

        void Swim();
    }

    internal class Tiger : Creature, ICreature
    {

    }

    internal class Horse : Creature, ICreature
    {
        public override void Walk()
        {
            throw new Exception("Can walk");
        }
    }

    internal class Fish : Creature, ICreature
    {
        public override void Walk()
        {
            throw new Exception("Can walk");
        }

        public override void Run()
        {
            throw new Exception("Can Run");
        }
    }

    internal class Tortoise : Creature, ICreature
    {
        public override void Run()
        {
            throw new Exception("Can Run");
        }
    }

    public static class Factory
    {
        public static ICreature CreateTiger()
        {
            return new Tiger();
        }

        public static ICreature CreateHorse()
        {
            return new Horse();
        }

        public static ICreature CreateFish()
        {
            return new Fish();
        }

        public static ICreature CreateTortoise()
        {
            return new Tortoise();
        }
    }
Dirk Bahle 27-Sep-18 10:06am View
   
It looks like it happened again:
https://www.codeproject.com/Answers/1261498/Best-way-to-design-my-classes-for-the-requirement#answer2

This makes me wonder if this is the same person maybe trying to resolve a personal issue with me or CP ...?
Dirk Bahle 24-Sep-18 4:00am View
   
Thanks, strange - I cannot see a reason for voting this with 1 star?
Dirk Bahle 16-Sep-18 3:21am View
   
Not sure about your code - its hard to tell what it is supposed todo but I wrote an article on tree view traversal in WPF and it might help you with WinForms as well since both are build on C#/.Net. If anything, you could use the article to verify if your algorithmic coding looks similar to what I posted or not. Just look through my articles and find the TreeView article on level order traversals ...
Dirk Bahle 13-Sep-18 15:46pm View
   
Yes, thats what I had in mind, you could, depending on the number of your data points and the number of points you need to show build different levels of aggregated/averaged views - Say, you have a detailled table with the raw data (level 0), then you could have a level 1 data table where every data point in level 1 represents the average value of the last 100 data points in the level 0 table.

Depending on your need you could average over 1000 instead of 100 points or you could use multiple levels of aggregated tables level 0, level 1, level 3 ... where the first table contains all the raw data and every other table averaged values over 100 points in level 0, 100 points averaged over level 1 ...

'Obviously', youre tables will get smaller as the level 0,1,2 ... increases and you can also support different views of details in your chart. The update should be much difficult either since you would compute the averages only every 100 or so record...
Dirk Bahle 8-Sep-18 10:57am View
   
Not sure if it helps, but it might be something to consider.
Here is an example of a control that will watch the DataContextChanged event and attach itself to a viewmodel that implements the IEditBox interface:
https://github.com/Dirkster99/InplaceEditBoxLib/blob/master/source/InplaceEditBoxLib/Views/EditBox.xaml.cs

Doing so allows the viewmodel to bubble notifications through the control. This means the viewmodel does not have to worry about the UI part of the notification - its worring about the required event only ...
Dirk Bahle 8-Sep-18 10:50am View
   
An association between viewmodel and usercontrol via datacontext is in principal OK - but there are technical reasons why events/commands should be with their particular patterns ...
Dirk Bahle 8-Sep-18 4:54am View
   
Hi I am not sure what your exact question is but you should research behaviors https://stackoverflow.com/questions/8360209/how-to-add-system-windows-interactivity-to-project

or 'attached behaviors' if you want to propagate events from a WPF control to the viewmodel using command binding (if you cannot change the source code of the control)
Dirk Bahle 18-Aug-18 11:59am View
   
Yes, software companies usually buy the service from a translation agency to translate from English to Chinese, English to German and so forth, open source works similar but usually without the money aspect.
Dirk Bahle 18-Aug-18 8:55am View
   
OK. You want to follow a process and you should have a tool that supports your process. In my case, I've been using a tool to translate fomr a base language into any other language

https://github.com/Dirkster99/Locult

The tool consumed resx files and produced matching resx files based on a language translation service. It was free and easily to use until Microsoft required the use of a credit card - that said, its still free but I have to up date for the new API before it will work again.

You could use a similair file based approach (resx, csv, xml), because most translators won't be able to deal with your database directly and you probably want to limit access anyway.
Dirk Bahle 3-Aug-18 3:31am View
   
Not sure what your question is - you are showing only controls but no model or viewmodel. To hard to read your mind :-(
Dirk Bahle 21-Jul-18 10:57am View
   
I guess one can post as many solutions as one can - I saw the first solution - but do your really think this long winded support is worth three stars only? Anyway, it does not matter - I hope you get to implement something cool now :-)
Dirk Bahle 21-Jul-18 5:56am View
   
You need to explain more how your current solution works - and then - maybe someone can suggest an improvement. Currently, its not clear if you use ASP.NET, WPF, or WinForms etc... each UI Framework has its own problems and if you cannot explain in detail what your problem is nobody will be able to give you a detailled solution :-(
Dirk Bahle 20-Jul-18 5:27am View
   
Well, you could post the code for the App.xaml, the resource dictionary and the usercontrol directly in the post (using a Pre tag) or you could use DropBox, OneDrive or whatever other oline resource is available (the later would be best since I could actually load the project in VS and have a look at it - you can usually strip down the number of files by concentrating on those that are relevant to the problem - I often disctovered the solution myself when I was about to post a question. Just look at some other entries and you will see what others do ...
Dirk Bahle 19-Jul-18 17:40pm View
   
Sorry, but I need more complete XAML sample code that what you are showing. I cannot tell what you are trying to do nor how to fix it based on XML snippets only - please list a more complete XAML listing.

The problem of non-existant reference can be due to a number of things - it starts with a male-formed reference and ends with an internal class deifnition any many other problems in between - you need to list more code (a complete project/solution would be best) to expect helpt on this on I am afraid...
Dirk Bahle 14-Jul-18 6:14am View
   
You need to show the C# code you converted from - people are otherwise required to employ mind reading techniques to understand your problem and device a correct solution.
Dirk Bahle 29-Jun-18 11:14am View
   
You do not have to do the layouting via Regions just because you use PRISM. The normal layouting via XAML is still available - in my case I am using AvalonDock to the layouting for documents and tool windows which works well if you are interested in a document oriented application. You can review this project to understand how it works:
https://github.com/Dirkster99/Edi

(or follow my tutorial on AvalonDock if you are interested in that)
Dirk Bahle 27-Jun-18 15:59pm View
   
This question cannot be answered unless you show at least the code for the template seletor.

Have you tried to set a break point in the template selection method of the LabelTemplateSelector? What happens there? Could it be that the template selector returns null under some conditions?
Dirk Bahle 18-Jun-18 6:07am View
   
No problem, glad to hear it helped - You should set the stars for the answer to indicate the answer for others who may be searching a resolution for the same problem ...
Dirk Bahle 1-Jun-18 5:55am View
   
I can compile your code now but I get 2 error messages in the Output TW of VS:

System.Windows.Data Error: 40 : BindingExpression path error: 'Message' property not found on 'object' ''MainWindow' (Name='')'. BindingExpression:Path=Message; DataItem='MainWindow' (Name=''); target element is 'ListView' (Name=''); target property is 'ItemsSource' (type 'IEnumerable')
System.Windows.Data Error: 40 : BindingExpression path error: 'Message' property not found on 'object' ''MainViewModel' (HashCode=24112512)'. BindingExpression:Path=Message; DataItem='MainViewModel' (HashCode=24112512); target element is 'ListView' (Name=''); target property is 'ItemsSource' (type 'IEnumerable')

These messages indicate that your code wants to bind to a property called Message (see XAML code) but the MainViewModel class does not contain a Message property.

The MainViewModel class only contains a Message class. But that class cannot be considered for binding - only instantiated object properties are relevant here.

I think you need to change the binding expression to:
ItemsSource = "{Binding Client}"

The 2nd Problem I found is in the root of the MainWindow.xaml - you need to remove the binding statement: DataContext="{Binding RelativeSource={RelativeSource Self}}" since this tells the MainWindow to look on its on object instance for the mentioned properties.

This is probably the fix to make changes visible in the UI. If have further problems it would be easier if you take a break from this and complete a tutorial on WPF... maybe commiting the sample code to a GitHub repro could also make it easier to find and fix further problems ...
Dirk Bahle 30-May-18 8:00am View
   
I tried to compile your project but I cannot seem to find the definition for 2 methods:
- I cannot find a definition for the HexEncoding method
- I cannot find a definition for the Write method stated in the button click event handler _main.Client.Write(data);

- Can you update to include these?

- I guess you are using MVVMLight, right?
Dirk Bahle 29-May-18 2:23am View
   
This sound like you are missing a NotifyProperty Changed event in your viewmodel but its really difficult to tell from a narrative description - is it possible to share a sample code project that shows the problem (here or on GitHub)? I'd be curious to look at it and try to see if I can find a fix ...
Dirk Bahle 28-May-18 7:19am View
   
Not sure why this works in VB.Net - but foreach will work as long as you do not change the collection you are iterating over - so its quit likely that you either do not change the source collection - or if you change it - the change is (implicitely?) applied after the collection is iterated over ...
Dirk Bahle 17-May-18 5:17am View
   
I am not sure what you exactly want to do so I cannot give you a complete solution but since this asks to display the values for each key, this is how it should work (I cannot test the code since I do not have sample data):

int columnindex = 43;
List<string> lst = new List<string>(); // declare "lst" here

foreach (DataRow row in dtFarmerFarmReports.Rows)
{
var dict = JsonConvert.DeserializeObject<Dictionary<string, string>>(row["farm_detailsdata"].ToString());

foreach(KeyValuePair<string, string> kvp in dict )
{
Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
}

string str = string.Empty;
lst.AddRange(dict.Keys);
lst.AddRange(dict.Values);
}
Dirk Bahle 15-May-18 3:22am View
   
DataContractSerializer is the better solution since its much newer etc... (just to be clear)
Dirk Bahle 26-Apr-18 7:56am View
   
OK, so we eliminated 2 possible problems - a third frequently occuring problem is that your viewmodel does not implement the INotifyPropertyChanged interface - which in turn, sometimes leads to a situation you are describing:

- a value is displayed if the timing is lucky (on your old cumputer)
- a value is NOT displayed if the timing is such that the view is constructed and the value is changed (without notification) in the viewmodel after the construction of the view.

The public void CreateCrazy(object para) method looks strange to me. Try using the Observable Collection without a new constructor everytime you execute the method. You should instead:
1- construct the ObservableCollection in your standard constructor (only ONCE)
2- use Clear(), Add(), Remove() methods to manipulate the data in the collection

Does that change your problem in any way?
Dirk Bahle 11-Apr-18 8:16am View
   
It would be helpful if you could include class names in your code listings. You should be aware that ListBox bindings usually require 2 viewmodels:
- one that contains the collection eg.: ObservableCollection<courseitem> bound to the ListBox's ItemsSource (this viewmodel can be attached to the MainWindow's DataContext)
- and one that represents an item that is displayed in the list of the ListboX (e.g.: CourseItem)

Here is a sample that demonstrates what I mean:
https://www.codeproject.com/Tips/806587/Basic-MVVM-Listbox-Binding-in-WPF
Dirk Bahle 11-Apr-18 8:10am View
   
OK it looks like you are on track towards understanding your problem with these BindingExpression errors:
System.Windows.Data Error: 40 : BindingExpression path error: 'CheckCommand' property not found on 'object' ''Cours'

means that .Net attempts to bind you command property from the checkbox as specified with:
Command="{Binding CheckCommand,Mode=TwoWay}"
. to an object of type 'Cours' but cannot do it because the command property is simply missing (or not public) at the 'Cours' class.

The second error refers to the IsSelected property binding which can also not be bound because you are missing the property in the viewmodel that is attached to the MainWindow's DataContext.

You cannot expect that the Command binding will invoke the event handler: CheckBoxCourses_Checked as these are, albeit similar, completely different ways of getting a processing request done.

You should research MVVM and WPF Binding tutorial based on simpler scenarios to understand better how this works. This Tutorial maybe helpful:
http://www.wpf-tutorial.com/data-binding/introduction/

You will see similar error messages when you implement one of their example and then (willingly) change a binding specification such that it will not find a property in the viewmodel (e.g.: specify 'XXXX' instead of 'IsSelected'). Otherwise, there are plenty of MVVM WPF examples here on CodeProject.
Dirk Bahle 11-Apr-18 4:35am View
   
This thread may be related to your problem: https://stackoverflow.com/questions/21193242/wpf-checkedlistbox-how-to-get-selected-item
Dirk Bahle 9-Feb-18 14:26pm View
   
OK, make sure its not the Explorer with its Preview pane (use a shortcut to start your test after reboot).

If thats not it, investigate into the other direction, your program must be blocking your own access, put a breakpoint or similar guard - everywhere you open the file - there must be an event or process you are sometimes doing more than once and it sometimes produces this lock, right?
Dirk Bahle 1-Feb-18 16:30pm View
   
Did you actually notice that the article reference is relevant?

So, I can only write an article OR answer Q&A but not both, is that right?
Dirk Bahle 1-Feb-18 11:34am View
   
Oh OK, I saw it listed in the front page and thought the question was current - rep-point farming is a funny term :-) thats mot my intention but we can include any other link to any other article if you happen to know one that answers this particular question - I really don't know one which is why I wrote the article in the first place :-)
Dirk Bahle 12-Oct-16 13:42pm View
   
I don't need to know a lot of reasons I need to know a way to solve the problem described. So far, I've looked only here;
https://github.com/firstfloorsoftware/mui/tree/master/1.0/FirstFloor.ModernUI

and found that the dark context menu is not working there either.

Its working here:
https://github.com/MahApps/MahApps.Metro/blob/develop/MahApps.Metro/Styles/Controls.TextBox.xaml

...and I found that it is working because the TextBox is restyled with the context menu property:


So, thats how it works for me too.