Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
J

Jean Louis Leroy

@Jean Louis Leroy
About
Posts
29
Topics
12
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • MVVM: Transfering data from ViewModel to Model, when and how ? [modified]
    J Jean Louis Leroy

    Pete O'Hanlon wrote:

    Why do you think it makes modal dialogs difficult to implement? I've never found that to be the case.

    I suppose that many get their first exposure to MVVM via Josh Smith's article. But his sample app doesn't contain any modal dialogs. However, it's still one of the first things you need when implementing a real app. So when you turn to Google and search for "MVVM modal dialog" you get flooded with solutions falling roughly in five families: use a control; use a service; overlay a control on your view and disable its controls; what the heck, a bit of code-behind won't hurt; and finally, don't do modal, it's so nineties. It seems that no consensus has emerged on the issue yet (or I've missed it). Not that I care that much about consensus anyway, but, by design or by accident, it's a difficulty for newbies... What solution do you use ?

    WPF wpf architecture question announcement

  • MVVM: Transfering data from ViewModel to Model, when and how ? [modified]
    J Jean Louis Leroy

    Jean-Louis Leroy wrote:

    I want to support the New/Open/Save/SaveAs cycle for Reports [...] But how do I implement SaveAs ? By the time I know the end user wants to make a new object, the old one has already been messed up.

    Thinking about it, one solution out of this problem is to drop the SaveAs command (posterior to changes) and replace it with a Duplicate command (prior changes). Like in Mac OS X Lion :laugh: Then what would Save mean ? Worse, what would it mean if a user changes the data, then never executes Save ? It seems to me that MVVM may end up curbing the way we design UIs. Another example, it discourages modal dialogs, or at least it makes them difficult to implement. I wonder if it's legitimate for a code pattern to have such impact on the end-user experience. Isn't it the tail that wags the dog ?

    edit: grammar

    WPF wpf architecture question announcement

  • MVVM: Transfering data from ViewModel to Model, when and how ? [modified]
    J Jean Louis Leroy

    (quotes no in the same order as in the original text)

    SledgeHammer01 wrote:

    DocumentViewModel should DEFINITELY NOT have its own string Content property. It should simply *wrap* the one from the Document(Model).

    Here I stumble upon a difficulty. Consider a Person that has a birth date stored in a DateTime. Obviously we don't want to present that in the VM. Instead we want to map the double Person.BirthDate to a text input field in the view - or three text boxes for day, month and year, or some Calendar control. So what's the VM between View and Model going to look like ? Does it contain one (or three) string properties ? Hmm, maybe something like this ?

    public string Day
    {
      get { return \_person.BirthDate.Day.ToString(); }
      set { d = \_person.BirthDate.AddDays(int.Parse(value)).AddDays(-\_person.BirthDate.Day); }
    }
    
    public string Month
    {
      get { return \_person.BirthDate.Month.ToString(); }
      set { d = \_person.BirthDate.AddMonths(int.Parse(value)).AddMonths(-\_person.BirthDate.Month); }
    }
    
    public string Year
    {
      get { return \_person.BirthDate.Year.ToString(); }
      set { d = \_person.BirthDate.AddMonths(int.Parse(value)).AddMonths(-\_person.BirthDate.Year); }
    }
    

    Or maybe a ValueConverter is used somewhere ? I haven't explored that yet...

    SledgeHammer01 wrote:

    Rule #1 in good software design, ESPECIALLY in WPF & MVVM... is that you should only have one instance of an object in memory at all times

    I do see your point with having only one instance of an object in memory at all times...especially since I have implemented object-relational mappers like Perl's Tangram. If I have two views looking at the same Model at the same time, I'd want the changes made via one view to be reflected in the other view. Right ? And binding to the Model's property instead of copying them gives me just that. Or does it ? Back to my Person.BirthDate example, suppose that I have VM1 that exposes the birth date as a single string property (BirthDate) in yyyy/mm/dd format. When the View sets the VM's BirthDate property the Model.BirthDate is updated. Now VM2 uses three string properties: Day, Month and Year. But changing the birth date via VM1 fires a "BirthDate" event that is significant only to the View that displays VM1. The change notifications are sent as changes to th

    WPF wpf architecture question announcement

  • MVVM: Transfering data from ViewModel to Model, when and how ? [modified]
    J Jean Louis Leroy

    Hmm, I don't think I have a "fundamental misunderstanding". In my app the ViewModel does not store or load data by itself - it tells a DAO to do so. As for validation, it asks the Model to do it. Ok, let's imagine that we rewrite Notepad the MVVM way. We have a Document object with a string property - say Content. And a DocumentViewModel that holds a reference to a Document. It has a a string Content property too, which is loaded from the underlying Document. And then a DocumentView with a text box that binds to the DocumentViewModel's Content. I know I could bind to Document.Content directly but I've beaten that horse in my original post already. Am I on the right track here ? Now loading the ViewModel from the Model has been dealt with but what about the data flowing back from Mr/Ms User to the View to the ViewModel to the Model ? My current take is this… ViewModel exposes commands such as NewCommand, OpenCommand, SaveCommand, SaveAsCommand - and then some more like Copy/Cut/Paste Commands. NewCommand.Execute checks whether pending changes exist and possibly offers to save. Then it sets the VM's Document to a "new Document()". The VM updates its Content property and fires an event. SaveCommand.CanExecute returns True if the document has been changed. SaveCommand.Execute copies the text from VM.Content to Document.Content then tells some object to save the document - via an interface so it can be mocked and unit-tested. SaveAsCommand.Execute…hmmm…I guess it sets the VM's Document to a "new Document()" before transferring the VM.Content to Document.Content. But this assumes that the VM has copied all the Document's information. Or maybe the Document is cloneable and we replace the VM.Document with VM.Document.Clone() ? Now in my real app, it's a bit messier because the Document is a composition of other objects that have their VM too.

    WPF wpf architecture question announcement

  • MVVM: Transfering data from ViewModel to Model, when and how ? [modified]
    J Jean Louis Leroy

    I don't bind the view directly to model properties, and I don't want to change that. For starters, I don't like it. Moreover, in the general case it is not always possible. The ViewModel may contain properties that have no direct counterpart in the Model. Also my Model objects contain collections. So I would need to use ObservableCollections...but they're pulled from a Hibernate session so I don't even have control over the exact type of the collections.

    WPF wpf architecture question announcement

  • MVVM: Transfering data from ViewModel to Model, when and how ? [modified]
    J Jean Louis Leroy

    Hello, There's a lot of talk on the net about the View-ViewModel interaction but little about the ViewModel-Model interaction. I have a Report that has (as a composition) a collection of Parameters. So I have a ReportViewModel that has a collection of ParameterViewModels, a ReportView bound to the ReportViewModel, and the ReportView in turn carries an ItemsControl-full of UserControls bound to the ParameterViewModels. The ReportViewModel's constructor gets passed the Report object and passes the Parameter objects in turn to the sub-viewmodels. The Views and ViewModels interact nicely, the ViewModels "load" themselves from the underlying Models. More precisely, they keep a reference to the Model and synthesize whatever information the View needs. Now for what puzzles me: when/how does the data flow back from ViewModel to Model ? When/how does the user's gesturing finally impacts the Model ? I see that there are at least two possibilities... 1/ Live-update the Model whenever the ViewModel changes. Whenever we want to run operations on the updated Report, there's nothing extra to do. 2/ Implement an explicit "Apply" method in both ViewModels - obviosuly ReportViewModel.Apply will call ParameterViewModel.Apply. Whenever we need an up-to-date Report, first call Apply then save it somewhere, or print it, whatever. What's your take on this ? Jean-Louis

    modified on Tuesday, July 19, 2011 7:49 AM

    WPF wpf architecture question announcement

  • Using XAML for business objects
    J Jean Louis Leroy

    Okay, I found how to make it compile: remove the assembly directive from the namespace declaration:

    ...

    This works:

    ...

    Now for my other question, where did the compilation product go ? And more importantly, how do I get at it ?

    WPF question csharp dotnet visual-studio wpf

  • Using XAML for business objects
    J Jean Louis Leroy

    This is a follow-up to http://www.codeproject.com/Messages/3896423/Create-business-objects-from-XML.aspx[^] for which I didn't get any answer. I'm experimenting with the idea of putting a static set of pre-defined business objects in a assembly (CRRT.Domain) by means of XAML. I have a ReportDefinitions.xaml file containing this:

    Alas I get the following message: error MC3074: The tag 'ReportDefinition' does not exist in XML namespace 'clr-namespace:CRRT.Domain;assembly=CRRT.Domain'. Line 3 Position 3 What's wrong ? I checked that the classes do exist (in the proper namespace). And by the way, should this eventually work, where would the result of the compilation go ? In a resource ? I stumbled upon this last question by accident btw, my initial plan was to incorporate the XAML as a text resource and load it using XamlReader. But Visual Studio spotted the .xaml extension and created a build step.

    WPF question csharp dotnet visual-studio wpf

  • Create business objects from XML
    J Jean Louis Leroy

    I have a C#/WPF app where all the logic is coded in the dialog boxes. Pretty much like an Access app in fact. I'm re-architecturing it into a MVVM app. Some of my business objects (of type Report) live in a (legacy) database and are created upon user interaction. Some others (of type ReportDefinition and ReportParameter) are from a pre-instantiated set of read-only objects. ReportDefinition objects are identified by a key. In the Access-style app I could use XAML to create a resource dictionary indexed by the ReportDefinition key. It would be very easy to define the various ReportDefinition objects, along with their arrays of ReportParameters in XML. The objects would be readily accessible from my code. How can I achieve a similar thing in the business layer of the new app ? I guess that I'm longing for a sort of XAML-sans-View. I can imagine options based on XmlSerializer but maybe I'm overlooking a very simple and elegant solution. Any suggestions ?

    .NET (Core and Framework) wpf csharp question database business

  • Stretch StatusBarItem
    J Jean Louis Leroy

    It works perfectly, thanks a lot !

    WPF question

  • Stretch StatusBarItem
    J Jean Louis Leroy

    I'm trying to make a StatusBar with four text items distributed evenly across the available width like this:

    -----------------------------------------------------------------
    | status1 | status2 | status3 | status4 |

    Instead I'm getting this:

    -----------------------------------------------------------------
    | status1 | status2 | status3 | status4 |

    ...when I use the following code, which looks like it should do the trick:

    What's wrong ? Thanks, J-L

    WPF question

  • Make two listboxes have the same width
    J Jean Louis Leroy

    Indeed the Grid containing the Listboxes was inside a StackPanel inside a ScrollViewer with HorizontalScrollBarVisibility="Auto". Which caused the problem. Thanks for helping, J-L

    WPF question css wpf wcf json

  • Make two listboxes have the same width
    J Jean Louis Leroy

    Ian Shlasko wrote:

    When you use star-sizing, the grid does NOT resize columns based on child control sizes... First it sets the size of fixed columns (Like your "40"), then it figures out the size of "Auto" columns by asking the controls in those columns what they need, then it splits up the remainder into the star-sized columns.

    That's the way I understand it. But I suspect that the listbox in turn examines the items to answer "what it needs". When I limit the number of characters in the text items for a test, everything works perfectly. So the content of the listbox does matter. I think.

    WPF question css wpf wcf json

  • Make two listboxes have the same width
    J Jean Louis Leroy

    Hello, I have two listboxes arranged side by side in a Grid control.

    I want both listboxes to have the same width, regardless of the (text) content of the listboxes. Initially, the left listbox contains a list of strings. The right listbox is empty. If the maximum width of the items in the left listbox is smaller than (roughly) half of the size allocated to the entire grid, everything is ok. Otherwise, the left listbox occupies whatever width is needed to display the widest visible item, and the other list gets the rest. I suppose that the grid "asks" each listbox what width it wants, and they in turn ask their items. I'd like to stop the process before the width of the items gets involved, IOW both listboxes should report minimal width, then the grid would have plenty of space on its hands, which it would split evenly between the two listboxes. How can I achieve that ? I've seen suggestions on the web, involving either SharedSizeGroup or disabling the listbox' horizontal scrollbar and setting HorizontalContentAlignment to "Stretch". They don't seem to work...I also tried binding the left listbox' MaximalWidth the the right listbox' Width, to no avail.

    WPF question css wpf wcf json

  • Pulling controls from resources
    J Jean Louis Leroy

    Ian Shlasko wrote:

    Ugh, typical unhelpful Xaml/Baml traces... Really wish Microsoft would put some useful information in there.

    Really wish Microsoft would give the source code like they used to for the CRT :laugh: I'm very happy with the Style-based solution, thanks.

    WPF database question visual-studio data-structures learning

  • Pulling controls from resources
    J Jean Louis Leroy

    Thanks for the very clear explanations and the suggestion about Styles. It looks like a better idea because - if I'm not mistaken - it will allow me to set other properties like Margin etc. Out of curiosity I still took a look at the stack trace in my control-in-resource approach. Here it is:

    PresentationFramework.dll!System.Windows.Markup.XamlParseException.ThrowException(string message, System.Exception innerException, int lineNumber, int linePosition, System.Uri baseUri, System.Windows.Markup.XamlObjectIds currentXamlObjectIds, System.Windows.Markup.XamlObjectIds contextXamlObjectIds, System.Type objectType) + 0x1bf bytes	
    PresentationFramework.dll!System.Windows.Markup.XamlParseException.ThrowException(System.Windows.Markup.ParserContext parserContext, int lineNumber, int linePosition, string message, System.Exception innerException) + 0x58 bytes	
    PresentationFramework.dll!System.Windows.Markup.BamlRecordReader.ReadRecord(System.Windows.Markup.BamlRecord bamlRecord) + 0x75f bytes	
    PresentationFramework.dll!System.Windows.Markup.BamlRecordReader.Read(bool singleRecord = false) + 0x1c bytes	
    PresentationFramework.dll!System.Windows.Markup.TreeBuilderBamlTranslator.ParseFragment() + 0xc9 bytes	
    PresentationFramework.dll!System.Windows.Markup.TreeBuilder.Parse() + 0xf bytes	
    PresentationFramework.dll!System.Windows.Markup.XamlReader.LoadBaml(System.IO.Stream stream, System.Windows.Markup.ParserContext parserContext, object parent, bool closeStream) + 0xc7 bytes	
    PresentationFramework.dll!System.Windows.Application.LoadComponent(object component, System.Uri resourceLocator) + 0x16e bytes	
    

    CRRT.exe!CRRT.WindowCounterpartyGroupRiskReview.InitializeComponent() Line 1 + 0xb bytes C#
    CRRT.exe!CRRT.WindowCounterpartyGroupRiskReview.WindowCounterpartyGroupRiskReview() Line 29 + 0x8 bytes C#

    WPF database question visual-studio data-structures learning

  • Pulling controls from resources
    J Jean Louis Leroy

    Is it possible to put controls in app resources and use then as elements inside a StackPanel ? A bit of context: I have a UserControl which I use like this:

            SELECT blablabla
          
        
        select rarara
          
        
        etc etc etc
    

    Each local:FeatureSelectionControl fetches a list of values from a database and lets the user choose one of more values. I will need to use the same FeatureSelectionControls (i.e. with the same Table/Label/SelectStatement combination) in a dozen of dialog boxes. Since the SQL may change I don't want to duplicate the elements all over. So I thought I'd put them in an application resource. But first let's try with a window resource:

    SELECT blablabla

    Now how do I put the control in the StackPanel's collection of children ? IntelliSense didn't suggest a element but I still tried:

    When I run it, I get a "first chance exception of type 'System.InvalidOperationException' occurred in mscorlib.dll - Additional information: Stack empty.". However, the preview in the Designer is just fine. Does this approach has any chance of working ? What am I doing wrong ? If it works, will I get a single instance of a control (as identified by the same key) shared between my dialogs ? Or is a new instance created each time I pull from the resources ? What are the alternatives (I see one

    WPF database question visual-studio data-structures learning

  • Bind a UserControl string array property to containing window
    J Jean Louis Leroy

    Ok I found the solution here: use a List instead of a string[].

    WPF data-structures csharp html debugging

  • Bind a UserControl string array property to containing window
    J Jean Louis Leroy

    Hello, I have a UserControl that exposes a Selection property:

    public partial class FeatureSelectionControl : UserControl
    {

    public string\[\] Selection
    {
      get { return (string\[\])GetValue(SelectionProperty); }
      set { SetValue(SelectionProperty, value); }
    }
    
    public static readonly DependencyProperty SelectionProperty =
        DependencyProperty.Register("Selection", typeof(string\[\]), typeof(FeatureSelectionControl), new UIPropertyMetadata(new string\[\] { }));
    

    I want to use it in a window and bind the control's property to one of the window's properties:

    Code behind:

    public partial class WindowCounterpartyGroupRiskReview : Window
    {
    public WindowCounterpartyGroupRiskReview()
    {
    CustomerGroups = new string[] { };
    InitializeComponent();
    }

    public string\[\] CustomerGroups { get; set; }
    

    This crashes with a "first chance exception of type 'System.NullReferenceException' occurred in PresentationFramework.dll Additional information: Object reference not set to an instance of an object". STack trace is:

    PresentationFramework.dll!System.Windows.Markup.BamlRecordReader.ProvideValueFromMarkupExtension(System.Windows.Markup.MarkupExtension markupExtension = null, object obj = {System.Windows.Markup.BamlCollectionHolder}, object member = null) + 0x52 bytes	
    PresentationFramework.dll!System.Windows.Markup.BamlRecordReader.ReadPropertyArrayEndRecord() + 0x5f bytes	
    PresentationFramework.dll!System.Windows.Markup.BamlRecordReader.ReadRecord(System.Windows.Markup.BamlRecord bamlRecord) + 0x636 bytes	
    PresentationFramework.dll!System.Windows.Markup.BamlRecordReader.Read(bool singleRecord = false) + 0x1c bytes	
    PresentationFramework.dll!System.Windows.Markup.TreeBuilderBamlTranslator.ParseFragment() + 0xc9 bytes	
    PresentationFramework.dll!System.Windows.Markup.TreeBuilder.Parse() + 0xf bytes	
    PresentationFramework.dll!System.Windows.Markup.XamlReader.LoadBaml(System.IO.Stream stream, System.Windows.Markup.ParserContext parserContext, object parent, bool closeStream) + 0xc7 bytes	
    PresentationFramework.dll!System.Windows.Application.LoadComponent(object component, System.Uri resourceLocator) + 0x16e bytes	
    

    CRRT.exe!CRRT.WindowCounterpartyGroupRiskReview.InitializeComponent() Line 1 + 0xb bytes C#

    However, whe

    WPF data-structures csharp html debugging

  • Sorting a listbox when SortDescription won't cut it [modified]
    J Jean Louis Leroy

    SledgeHammer01 wrote:

    BindingListCollectionView implements everything you need. Like Comparer for example

    ...but the Comparer property is read-only :sigh: And it has the SortDescriptions but it's useless for my purpose... X|

    WPF question algorithms debugging announcement
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups