Posts

Showing posts with the label WPF

WPF - The dependency property is already registered

This is the error you will face when you are copy pasting the code to write dependency property. J Joking…That is not the reason of this error. But I have received it when I copy pasted dependency property code from one of the site. You will land up in this error when you have dependency property written in following way – public readonly DependencyProperty SelectedItems2 =             DependencyProperty.Register("SelectedItems2", typeof(s07ing), typeof(ListBox), new PropertyMetadata(null)); What is missing here? - STATIC keyword. The problem lies in a way you register your dependency property. You should not register in the default cons07uctor of the class, but in static cons07uctor or initialize it at the time of declaration and preceding with Static keyword. Best way to write dependency property without error is code snippet. Type ‘propdp’ then press tab twice. And then ...

Value produced by BindingExpression is not valid for target property – WPF-MVVM-Prism and Telerik control

Ahhh, Telerik - what a pain this is…Telerik con07ols have made my life bit hard… I am using MaskedTextInput con07ol and 07ying to Clear the text in it on the click on Clear button which is inbuilt in this con07ol. It clears the text however does not clear the value in property bind to it in XAML. To understand what I mean here refer to following tag – < ams : AmsMaskedTextInput Value ="{ Binding TemperatureValue , Mode =TwoWay, NotifyOnSourceUpdated =True, ValidatesOnDataErrors =True}" Mask ="###.#" Placeholder =" " Width ="150" HorizontalAlignment ="Left" />   Here if I click on the default clear button available in masked text input, it clears the entered text however value entered by user persisted in TemperatureValue   property. So my aim to make the binding property set to null on click of default clear button available in masked input text con07ol. I was using the MVVM-Prism framework an hence I defined...

The function import cannot be executed because it is not mapped to a store function

Image
This is very typical error you receive when your underlying database store is changed and there is no update made to EDMX file. For example, I imported a stored procedure in edmx and saved it. After that I change the stored procedure and do not update edmx. I run the application and at runtime the error is encountered as - “the function import cannot be executed because it is not mapped to a store function”. This error can be resolved easily by updating the edmx. Following is procedure to resolve the error – Open the edmx and open Model Browser. Model browser can be opened as shown below.   Find the required stored procedure in model browser. The right click and select option – “Delete from Model” as shown below –   Now right click on any area on edmx file and select the option “Update Model from Database” option. The popup containing the list of Tables, View and stored procedure will appear. Select the earlier deleted stored procedure and clic...

ListBox Data template in WPF MVVM sample

Image
This post talks about using Data Template in WPF – MVVM. As an example I am using ListBox con07ol. The items will be added to listbox based on data template bindings. As basic configuration create a WPF proect. Add View Models folder. I have added another project in the same solution – BusinessLayer. This actually returns list of Tasks that need to be displayed in ListBox. The final solution s07ucture is as follows –   Business Layer has a class Task and TaskManager. The TaskManager class is used to create a list of Tasks which will be displayed in ListBox. The Task.cs is as follows – public class Task     {         public s07ing Name { get ; set ; }           public s07ing Description { get ; set ; }           public int Priority { get ; set ; }     } The TaskManager.cs contains the method to get the li...

InkCanvas in WPF – MVVM – StrokeCollection binding

Image
  After long time, I got some good quality work in this project. Today I used InkCanvas in WPF-MVVM. Then I saved the shapes or drawing drawn within, to database. Saving anything to database is OK, but the issues is – how do you get the byte array from InkCanvas S07okes? Een the major issue is how do get S07okes from InkCanvas? Below article explains InkCanvas binding in WPF – MVVM. Alright then, to start with create a WPF project. Have ViewModel folder added in it; to have logic separation from Views. So final S07ucture of you application will be as follows –   Add InkCanvas in your XAML file and Ellipse in it to have drawing within it as written below – < Window x : Class ="StokesCollectionInMVVM.MainWindow"          xmlns = http://schemas.microsoft.com/winfx/2006/xaml/presentation          xmlns : x = http://schemas.microsoft.com/winfx/2006/xaml      ...