.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

ContextMenu ItemsSource Converter not called

Posted By:      Posted Date: September 29, 2010    Points: 0   Category :WPF


I have the following problem:

I would like to show a context menu in a list view depending on the selected items of the list view. What I did so far:

I created a listview and assigned a context menu to it. Then I binded the ItemsSource property of the context menu to the SelectedItems property of the list view and assigned a converter for this binding to do some special handling depending on the selected items.

When running the application I recognized that the converter will not be called every time the context menu pops up. It seems like that if you switch the context menus very fast (by right clicking on different items in the list view in very short intervals) the converter will not be called, but if you click with a lower frequency (or just wait one second or two until you release the right mouse button again) everything works fine.

I have the following code sample which reproduces the issue on my machine. The code just creates a list view, fills it with some example strings and implements a converter which just increments a static int every time the converter of the context menu is called.

To check if the problem is really the converter and not an update of the ItemsSource, you can uncomment the first context menu in the xaml file and comment the second one, then you will recognize that the context menu will show the cor

View Complete Post

More Related Resource Links

.net code converter

For coverting your programming langugae to another languge the below site is very help full


Web Q&A: Who Called the Script?, Concatenating Binary Files, and More


This month find out which part of an HTML document has called a script, how to concatenate binary files, find a node, reference one script from another, build a GUI database front end in Access, and compare XML files.

Edited by Nancy Michell

MSDN Magazine August 2003

Convert .docx to web page - "the converter cannot complete the task because an internal error occurr


I'm trying to convert docx files to webpages to be published in to a library elsewhere on our sharepoint site. At first I was having no problem, the files were converting, however more recent files have returned the error: the converter cannot complete the task because an internal error occurred

I've tried writing, uploading and converting a simple docx file, and this works which has led me to believe that the problem is something in the docx files that i'm trying to convert. So i tried using word07 to clean the documents up by clicking Office button>prepare>inspect document then removing all the metadata, custom xml etc from the files resave, upload and convert, but still no joy.

I'd simply rewrite the document but the problem is that there are a lot of them.

Any ideas what's going wrong?


InfoPath Workflow Task Form "Loading" event handler only being called after App Pool recycled.


I have a Workflow that is using an InfoPath task form.  In the "FormEvents_Loading" method event handler I have some code that needs to run each time the form is opened.   I recycle the App Pool and open the form the code runs perfectly, but if I close and try to re-open the form the code is not run at all.  I can then recycle the App Pool again and on the next load the code executes just fine.   The code that is supposed to be run is a very simple statement to set a field value, so I don't think it is interfering.

Does anyone know what this might be?


Customizing the Converter for Json.NET


Many recently days, I thought about Json.net library that implemented by James. It is really a good library that I have ever used. I really impressed about many Converters that this library expose for user. I can list some converter of json.net at here:

+ BinaryConverter
+ BsonObjectIdConverter
+ DataSetConverter
+ DataTableConverter
+ EntityKeyMemberConverter
+ HtmlColorConverter
+ IsoDateTimeConverter
+ JavaScriptDateTimeConverter
+ KeyValuePairConverter
+ RegexConverter
+ StringEnumConverter
+ XmlNodeConverter

As you see, json.net have many converters, but still not enough for our necessary. So in this post, I try to explorer about 2 converters that I thought it is very useful for us. That are ArrayConverter and Object Converter (it is named by me). In 2 converter, I mainly implement it for return the object's interface, so it can be re-use and extension better. Now this is my code for implement it:
+ CustomObjectCreationConverter

    internal class 

Trying to get SPSite when called through a web service


I have built a custom timer job that makes calls to a web service that I built.  The reason I built the web service is because I recognized that the sharepoint timer job does not have context for a site and I thought that by having the timer job call the web methods of the web service I could have the context that I desire.  This works great for accessing the web.config file, however, I have discovered that I am unable to get SPSite (SPSite oSite = new SPSite(AbsoluteURL)).  The constructor does not throw an error but I am unable to use the new object.  If I am able to get to the web.config and the site is a SharePoint site I figure I should be able to get an SPSite object.

I am trying to understand if I am running into a known scenario or if this should work and that I have a bug that I don't recognize.

WCF Service Function Getting Called Twice


I have a WCF Web Service.  I am trying to test the service from a web form.  The web form calls the service using WebOperationContext.  The call successfully sends, however the web service function gets called twice while stepping through the code.  Nothing happens in between the first and second function call.  Not even setup of the Service.  The function itself is building a Generic List<Of Type T> and adding objects to the list.  The odd thing that happens, if I do not make the call to the add function, the Service function doesn't get called twice.  I'm including the network log collected from the network layer.  I can provide more source code if need be.  

Custom Validation Attribute is not called by validation mechanism.

Hello everyone I have create custom validation attribute and assign it to class level validation. Unfortunately, it is not called. I try every way that it think it could be solve the problem. However, it take me for hours and I can't find the attribute is not called by validation mechanism.For illustrate you I put the following code.Attribute[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)] public sealed class BooleanDependencyAttribute : ValidationAttribute { private const string _defaultErrorMessage = "?????????{0}"; private readonly object _typeId = new object(); public string DependencyPropertyName { get; private set; } public string DependentPropertyName { get; private set; } public BooleanDependencyAttribute(string dependencyPropertyName, string dependentPropertyName) : base(_defaultErrorMessage) { DependencyPropertyName = dependencyPropertyName; DependentPropertyName = dependentPropertyName; } public override object TypeId { get { return _typeId; } } public override string FormatErrorMessage(string name) { return String.Format(CultureInfo.CurrentUICulture, ErrorMessageString,name); } public override bool

Adding ContextMenu to WorkflowDesigner View

Hello Everyone,      I am trying to add the ability to have a user highlight an activity subtree, then right click the mouse, then select "Extract activity".  Which will then take out the xaml (ModelItem) selected, create a new activity out of it, then insert this newly created activity in its place.  Right now I'm stuck on getting a ContextMenu to appear when I right click in the designer area.  I can get my custom context menu to work in other places on the same window however.  Does anyone know the solution to this problem?  Also, does anyone have any better suggestions as to how I might achieve the same end result in a more efficient manner? Thanks everyone, Bob

DataGrid ValidationRule or IDataErrorInfo validation code called multiple times for each data change

Following my enquiry regarding a problem in Datagrid validation, for which managing exceptions is apparently a problem, I tested the two other methods: using validation rules, or implementing the IDataErrorInfo interface. I ran into other problems there, more insidious this time. This has been done on Windows7 (32-bit), .NET 4.0.30319. 1) IDataErrorInfo When this interface is implemented, the this[string columnName] property is called four times for each modification: two times before the cell enters edit mode (with the old value in the corresponding property) two times when the new value has to be validated (with the new value) It strikes me as not really efficient, is there something wrong with my code? Here's the C# part: using System; using System.Windows; using System.Collections.ObjectModel; using System.ComponentModel; namespace DataGridTest2 { public partial class MainWindow : Window { ObservableCollection<User> users; public MainWindow() { InitializeComponent(); users = new ObservableCollection<User>() { new User { Name = "Teddy", Age = "2" }, new User { Name = "Avi", Age = "19" } }; datagrid.ItemsSource = users; datagrid.Focus(); } } public class User : INotifyPropertyChanged, IDataErrorInfo { string name; public string Name

Combobox SelectedValue with Converter and PropertyChangedCallback() is not working together?

Hi, I have a combobox, I want to have a PropertyChangedCallback and at the same time I want to bind selected value with IsEnable property of a Checkbox. Problem is when I add Converter Neither Converter gets called and nor the  PropertyChangedCallbac().   <ComboBox ItemsSource="{Binding Source={StaticResource EnumExportType}}" Name="CB_ExpType" SelectedValue="{Binding Path=ExpType, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged" /> Combobox is binded with static Enum resource EnumExportType. Selected value is Binded with a Dependency Property ExpType which is a Enum.   public ExportType ExpType { get { return (ExportType)GetValue(ExpTypeProperty); } set { SetValue(ExpTypeProperty, value); } } public static readonly DependencyProperty ExpTypeProperty = DependencyProperty.Register("ExpType", typeof(ExportType), typeof(ExportScreen), new FrameworkPropertyMetadata(ExportType.EntireProject, new PropertyChangedCallback(ExportTypeChanged))); this works fine On changing Item from combobox PropertyChangeCallback gets called. Now I want To bind the IsEnabled property of a Checkbox to the ExpType property and I use IValueConverter to convert the ExpType to the correct boolean value. <CheckBox Content="Test" Name="CHK_WithModels" IsEnabled="{Binding ElementName=CB_ExpTyp

ViewBase.ClearItem is never called

Hello, I'm currently playing with ListView.View property and the associated ViewBase class and during my tests I discover that my override of the ViewBase.ClearItem method is never called when I remove items from the source items of the ListView. Does someone has any clue about when the ClearItem method is called? How can I, in my ViewBase class, manage the suppression of some elements in the initial list? Thanks in advance for your answers! To illustrate this issue, I have created a sample application composed of a Window with two buttons and a list view: The list view is initialized with three values The first button ("remove") removes the last entry of the source The second button ("clear") removes all the elements of the list by calling the Clear() method The list view is associated to a ViewBase implementation that only trace method calls to the console Finally, I run the sample and have three calls of the PrepareItem method visible on the console. After that I click on the first and second button, the list is updated but the ClearItem method of the ViewBase was never been called. Here is a sample source code: First of all the XAML (MainWindow.xaml): <Window x:Class="Poc.ViewBaseIssue.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.c

OnPreRender method is Not called last because of objectDataSource

I have an Asp.net web form with several drop down list boxes on it. The way the code is currently set up is that the drop down listboxes are populated through use of an ObjectDataSource via a class named SpottedWeb, as referred to by the TypeName attribute. The problem is that sometimes I need to pre-select drop down list box items, but the ObjectDataSource seems to have the last say in loading the drop down listboxes. So any attempt to pre-select drop down listbox items is undone when my .Aspx code is executed. My attempt to fix this involved creating an OnPreRender method, because I thought it would have the last say with populating my listboxes. But this is not the case.So is there a way that I can have the OnPreRender method or some other C# method be called after the .Aspx page loads my drop downs with the objectDataSource? // Here is my OnPreRender method.         protected override void OnPreRender(EventArgs e)        {            base.OnPreRender(e);             if (Session["Indicator"] != null)            {                PrePopulateWebForm(); // Pre-Sele

How can I know that LoadingRowDetails will not be called?

Hello, I wan't to set this.Cursor = Cursor.Wait in the SelectionChanged event of a DataGrid, then when a (sometimes lengthy) process of loading the RowDetails is finished, set this.Cursor = Cursor.Arrow. Problem is that the LoadingRowDetails event is only called the first time the row is loaded. So I have 2 questions: 1. How can I know if LoadingRowDetails will be called or not? 2. Why does is take so long to load the row details if I put the a DataGrid inside of an Expander (see XAML below)?   Thanks, Bill MSDN Subscriber

how to control multiple and different ContextMenu?

I have a DataGrid (.Net 4), it got its own ContextMenu. at runtime, this DataGrid will have an Adorner dynamically created over it for custom drag-N-drop feature, and this Adorner/base also has its own ContextMenu. my problem is i wanna see the DataGrid's ContextMenu, but instead the Adorner/base ContextMenu shown. If i fool around with the mouse right-click over the DataGrid randomly/fast-clicking, sometime I can get 2 of their ContextMenu pops. how can i control, to only show DataGrid contextMenu pop, and stop the other shown?
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend