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

Top 5 Contributors of the Month
Post New Web Links

Defining your own commands

Posted By:      Posted Date: October 12, 2010    Points: 0   Category :WPF

I'm reading a book on WPF (WPF in Action).

I'm really starting to like the Framework. But I got stuck defining my own Commands.


<Window x:Class="WPF_Commands.MainWindow"
    Title="MainWindow" Height="350" 

View Complete Post

More Related Resource Links

ASP.Net Gridview Edit Update Cancel Commands

In ASP.Net 2.0, GridView Control also provides the functionality to edit and update the data retrieved from the database using CommandField template. You can cancel the action using Cancel Command of the CommandField. GridView consists of events that can be used to perform the actions like edit, update and cancel upon the Data items displayed in the ASP.Net GridView Data Control.

Advanced WPF: Understanding Routed Events And Commands In WPF


See how routed events and routed commands in Windows Presentation Foundation form the basis for communication between the parts of your UI.

Brian Noyes

MSDN Magazine September 2008

Cmdlets: Extend Windows PowerShell With Custom Commands


Jim Truher presents an introduction to writing and registering your own custom cmdlets to be used in Windows PowerShell.

Jim Truher

MSDN Magazine December 2007

.NET Reflection: Dynamically Bind Your Data Layer to Stored Procedures and SQL Commands Using .NET M


One major inconvenience of using SQL stored procedures from code is having to match type information. You have to write long wrapper functions around the procedures just to expose the data types. In the .NET Framework, however, the reflection services of the System.Reflection namespace allow you to query rich metadata that describe data types. This article explains how to use reflection in .NET to end your stored procedure nightmares. The author creates four custom classes, including one that generates a SQLCommand object based on the metadata of a method. Using this library, you'll be on your way to automating the generation of stored procedures.

Atif Aziz

MSDN Magazine August 2002

Defining session variables...



This is a pretty basic question.

I have some code where I need to define a session variable  however it's coming back as Nothing when the code is executed. Here's the code:

' Default Currency

REQCURR = Request.Querystring("p_DCURR")
'If not explicitly specified, try to get it from session

If (REQCURR = "") Then

     If (Session("REQCURR") <> "") Then
          REQCURR = Session("REQCURR")

          'Here is the session variable I'm trying to define:
          Session("REQCAD") = 0
          REQCURR = ""
     End If

End If


So, for some reason that Session("REQCAD") = 0 has no value instead of having a value of 0.

Any thoughts?


Selecting Particular Commands with sp_repldone

Is it possible to use sp_repldone to mark all commands distributed up to a certain point? We have a scenario where the log reader is unable to construct a command from one problematic command. Log Reader Agent failed to construct a replicated command from log sequence number (LSN) {0000fc2c:000afd81:0009}. Back up the publication database and contact Customer Support Services. (Source: MSSQLServer, Error number: 18805) In order to correct this problem we issue the following: EXEC sp_repldone @xactid = NULL, @xact_segno = NULL, @numtrans = 0, @time = 0, @reset = 1 EXEC sp_replflush GO Unfortunately, this marks all commands as being distributed, even the commands that occurred after the problematic one.  From BOL it seems as though it’s possible to mark the problematic command and all earlier commands as distributed. (With sp_repldone, you can manually tell the server that a transaction has been replicated (sent to the Distributor). It also allows you to change the transaction marked as the next one awaiting replication. You can move forward or backward in the list of replicated transactions. (All transactions less than or equal to that transaction are marked as distributed.)) Does anyone know how to do this? I found an interesting article which discusses this but it’s from 2003 so I’m reluctant to rely on it in a production system. http://www

A FocusScope Nightmare (Bug?): Commands Are Disabled

I've got a simple menu with some simple commands:   Code Snippet <Menu> <MenuItem Header="Edit"> <MenuItem Command="ApplicationCommands.Cut" /> <MenuItem Command="ApplicationCommands.Copy" /> </MenuItem> </Menu>     I've got a simple control:   Code Snippet <UserControl x:Class="WpfApplication2.UserControlRed" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Grid /> </UserControl>     The code-behind for this control enables handling the 'Cut' command: Code Snippet   public partial class UserControlRed : UserControl { public UserControlRed() { InitializeComponent(); this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Cut, this.OnCut, this.OnAlwaysExecute)); } public void OnCut(object sender, RoutedEventArgs routedEventArgs) { Console.WriteLine("Cut"); } private void OnAlwaysExecute(object sender, CanExecuteRoutedEventArgs e) { e.CanExecute = true; } }     This control is added to a simple page so it can be navigated to using a Frame:   Code Snippet <!-- The Menu Commands are enabed with this code. --> <Page x:Class="WpfApplication2.PageRed" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x=&

Drag and Drop Events binded to MVVM commands

Hi , I am developing the drag n drop functionality.. I want in my drop event my command from MVVM model should fire.. Can you help me in how to Map Drag drop events  into MVVM by Commands...

WPF, MVVM, Commands from buttons within a Listbox ItemTemplate? (code included)

I want to capture button clicks from within a list item row. Below I have tried to boil the problem down as much as I can. First, here is the xaml <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="test2.MainWindow" x:Name="Window" Title="MainWindow">  <Grid x:Name="LayoutRoot">  <ListView Margin="148,74,0,202" HorizontalAlignment="Left" ItemsSource="{Binding ListData}">   <ListView.View>    <GridView>     <GridViewColumn Header="Item" DisplayMemberBinding="{Binding ItemName}" />     <GridViewColumn Header="Options" Width="200" >      <GridViewColumn.CellTemplate>       <DataTemplate>        <StackPanel Orientation="Horizontal">         <Button Content="Reject" Height="20" Width="80" Margin="5,2" Command="{Binding Commands}" CommandParameter="RejectItem" /> 

Deactivate WPF commands globally (class registered)

Hello everyone, I need to deactivate the default WPF commands in a globally way, i'm talking about those that are registered as "class commands". Here's the reason : We are upgrading an old application to WPF, that application uses some key shortcuts that overlap with default wpf commands. I know that that should be a problem as commands attached to an instance have more "priority" than those that are attached to the "type" or "class". The problem is, we cannot attach the input binding (notacommand to disable the shortcut) to every instance. It will be, either overkill (modify all the styles) or almost impossible (controls instantiated by third party controls).   So, is there a way to disable wpf "class attached" commands in a globally way ? Thank you.

how to open ssh / secure shell connection using vb and run commands

Hi I need to open connection for Secure shell and run commands from a remote site i am using Vb.net   i have seen many component that can use but i would like to code by my own if i could please give me your brilliant ideas

Defining a custom style for a derived DataGrid

Hi all, Please tell me what I could be missing here. I am trying to define a very basic style for a derived DataGrid and it doesn't seem to take! In my dll project, I have this in the Generic.xaml: <Style TargetType="{x:Type local:MyDataGrid1}" BasedOn="{StaticResource {x:Type DataGrid}}"> <Setter Property="RowBackground" Value="#AAEAEFF4"/> <Setter Property="AlternatingRowBackground" Value="#00FFFFFF"/> </Style>  .. and this is how the derived grid is currently (pretty empty until I have this figured out): public class MyDataGrid1 : DataGrid   {     static MyDataGrid1()     {       DefaultStyleKeyProperty.OverrideMetadata(typeof(MyDataGrid1), new FrameworkPropertyMetadata(typeof(MyDataGrid1)));     }   } And in my Sample App's MainPage.xaml, I simply have this: <mygrids:MyDataGrid1 x:Name="dataGrid1" /> But, the alternating colors are not applied! Interestingly, in debugger I see that the properties are set to these values in this instance, but the for some reason while rendering, these values were not used! Please help. Thanks

defining dataset (Visual Studio 2008)

hii alli need to prepare a report as  a table. but my table needs to contain data from two schemas. so my doubt is, is it possible to set two dataset names for a table in its property?

Administrative Commands via XP_CmdShell in SQL Server 2005

SQL Server 2005: Microsoft SQL Server Enterprise Edition (64-bit) Microsoft Windows NT 5.2 (3790) SQL Version 9.00.3175.00   I have 2 identical servers... one for DEV and one for TEST. On the DEV server, I can use xp_cmsdhell to execute "administrative commands" such as NET SHARE and AT. On the identically configured TEST server, I can not. Those command return the "System error 5 has occurred. Access is denied" error. I CAN run other commands via xp_cmdshell (DIR, NET USE, etc.). This is true regardless of the account I connect as.   The SQL Server service accounts in both instances are domain accounts belonging to the local admin group.   I "know" that I ran across this when setting up the DEV server and am "fairly sure" I found a reference to a known problem with 2005's xp_cmdshell and administrative commands. But for the life of me I can not now find any such reference, nor can I find any differences between the DEV and TEST servers in the area of users, groups, policies, or anything else security-related. (99.9% of the internet searches I do end up being about either enabling xp_cmdshell -- done -- or setting up an xp_cmdshell proxy account -- not needed).   Any input is greatly appreciated.   Thanks! -dave

WPF on XP : commands 'canexecute' method slow ?

Hi, I've created an aplication with WPF. I use the command pattern (well known 'RelayCommand' implementation of ICommand, with boolean properties from INotifyPropertyChanged objects, e.g 'MyObject.HasChanges' with a custom 'Save' command to be available if HasChanges is true). The application is deployed on many computers, in different sites ; in some cases the commands seem to be too slow, or buggy : the controls like MenuItem, Button etc. on which the Command property is set can take several seconds to be updated (meaning e.g their IsEnabled property will be et to true after the CanExecute call, but after a strange delay). In all cases, the problem appears with XP ; some are SP2, others SP3 fully up-to-date via Windows Update. All have the .NET framework v.3.5 SP1, and that is regardless of the hardware performances considerations (some where I see this bug are Quad Core with 4 Go ram, and the application runs very well on some machines with Celerons and 1 Go ram...). Graphic cards can be differnts too : the problem appears with a NVidia, and with a ATI too. I tried a lot of things, including disabling AllowsTransparency, etc... Debugger can't help, I don't know what to try after that, please help ;) !If my english isn't perfect, please excuse me -- feel free to tell me.
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