.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

Setting the target of a command binding

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



I have a wpf rich text box that I open and show in a win32 application.

I declare the rtf box in a resource dictionary like so:





In another place, I have a wpf window which I use as a floating tool bar. I declare it in its own xaml, similar to the following:


<Window x:Class="BidiFix.SandBox.Window1"

View Complete Post

More Related Resource Links

DataTrigger - Binding Value Property to Target Controls Content Property

This Gives me an error..   <Style x:Key="radioButtonSelctionKey" TargetType="{x:Type RadioButton}">       <Style.Triggers>       <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}},Path=ValueText}" Value="{Binding Path=Content}">       <Setter Property="IsChecked" Value="True"></Setter>       </DataTrigger>       </Style.Triggers>       </Style> Is it valid to bind Value Property. If not then does it mean that the Value propety must always fix and can not be changed or Bound to any property Dose it mean that both of the way of setting Value proeprt are WRONG..? 1) Value="{Binding Path=Content}"> Or 2) Value="{Binding RelativeSource={RelativeSource Mode=Self},Path=Content}">

Command binding issue with using CommandReference and CommandGroup

I'm trying to write an app using the MVVM pattern but I'm running into an command binding issue. I'm trying to bind a button to multiple commands. To do this I'm using the CommandReference class (this is from the MVVM toolkit) and the CommandGroup class (I found this CodeProject). Here is a simplified version of my xaml: <Window.Resources> <c:CommandReference x:Key="TestCommand" Command="{Binding Path=TestCommand}"/> <c:CommandGroup x:Key="TestCommandGroup"> <c:CommandReference Command="{StaticResource TestCommand}"/> <c:CommandReference Command="{StaticResource TestCommand}"/> </c:CommandGroup> </Window.Resources> <Grid> <Button Content="Command Test" Command="{StaticResource TestCommandGroup}"/> </Grid> If I set the DataContext of the window to itself, this works just fine and the TestCommand will execute twice. The problem occurs when I want to follow the MVVM pattern and I set the DataContext of the window to a ViewModel. When I do this the button becomes disabled (I don't see any binding errors in the output window). I tried debugging this to see what was going on. If I set a breakpoint on the PropertyChangedCallback for the Command, I noticed the sequence this gets called is diff

Visual indication of whether binding target is 'dirty'

I would like to be able to show users whether data they can see is synchronised with the source object the control is bound to.  E. g. a text box receives an update from the data source so its background is set to white.  When the user starts typing the background is set to yellow.  When they press enter (running code to explicitly update the source) or the textbox loses focus or press escape (running code to revert to the source value), the background should revert to white.  If the source should changes while they're editing and the target updates, the background should also revert to white.  The aim of this is to make it totally clear the the user what data is committed and what is not.

First I tried to do this using an attached behaviour to handle SourceUpdated and TargetUpdated events from the textbox.  Unfortunately TargetUpdated only fired on they first time the textbox was updated and SourceUpdated never fired at all.  I assumed this might be because it was a routed event that was being handled elsewhere.  Unfortunately I wasn't able to get round this by calling TextBox.AddHandler with handleEventToo = True because SourceUpdatedEvent is not a member of TextBox.  I guess this means it's not a RoutedEvent because it belongs to a Binding object which is not

Binding GridView to a List and setting HyperlinkField


Hello all. I am new to using Data Controls and would appreciate your help. I have a List<string> that I want to use as a datasource for the gridview, making the column a HyperlinkField type and passing the value clicked in the column in the url. My code:

private void DoBind(GridView grid, List<string> Accounts)


Hyperlinkfield field = new HyperlinkField();

field.DataNavigateUrlFields = Accounts.ToArray();

field.DataNavigateUrlFormatString = _urlToRedirectFromGrid;

field.DataSource = Accounts;


grid.AutoGenerateColumns = false;



I can't get this to work. The page throws an AJAX null exception when this method is called.

Command Binding not working when the host control is added programatically in wpf


This is weird. I have a UserControl (MyControl) with a button inside. I have added a command to this button whose command target is another user control which is again added to the same window.

When I add the UserControl statically in xaml to the CustomControl's host space, the CommandBinding system works fine, where as the same doesn't work if the UserControl is added programatically (on Loaded event of this Window).

What could be the reason. Am I missing something in here ?!?


A better representation of my words as an image. Also I have uploaded my source code with binaries @ https://code.google.com/p/commandbindingsample/

Image @ http://codelog.blogial.com/files/scenario.png


how to set polygon points indexed member as binding target


i have defined MyThumb as custom class inheriting from Thumb

MyThumb.XProperty is defined as a dependency property

I would like to do the following in its loaded event

  MyThumb thumb = sender as MyThumb;

  Binding b = new Binding();
  b.Source = thumb;
  b.Path = new PropertyPath("XProperty");
  BindingOperations.SetBinding(polygon1.Points[0], thumb.XProperty, b);

is this possible?

thank you

Validation when adding a new item and no target to source binding has yet taken place


Using: WPF (.NET 4) with Entity Framework on a SQLCE database.

In my app, the user can edit existing employees and create new employees. The same UI control is used to add and edit. In the case of editing an Employee, the DataContext for the control is the Employee object of my Entity Framework context. It is updated through binding, and the SaveChanges method is called on my EF to update the database. In the case of adding and Employee, the DataContext is a new Employee object, which will gets added to the EF and then saved. Simple.

I've been trying to hook-up validation to the control. I'm using WPF's ValidationRule objects for each field binding as required. When the field loses focus (as is the default action for a target to source binding), the validation rules are checked, which can incur an error. I can then check for the presence of these errors before allowing the employee to be saved.

But when adding a new Employee, if I go ahead and push the Save button without doing anything else, no validation takes place, becasue the bindings have never attempted to update the source! It just throws an exception as expected.

What can I do? I have ideas which would probably work, but I thought I should post here first in case I am missing something obvious! Is there a standard way to deal with t

Binding Command Inside DataGrid Using MVVM

In this post I will show you how to bind the commands inside the data grid control using MVVM pattern. For this post I have continue my last post which is used to explain the data pager using MVVM. For this post I have added DelegateCommand class which is added in the Classes folder. I have only one command in the viewModel (with the name HomeViewModel and is located in the ViewModel folder). The view for the Home is located in the View folder. Here you can see that I have added the HomeViewModel as resource in the home view which you can see in the Image 1.

Binding WPF Controls to an Entity Data Model

In this interview, programming writer, McLean Schofield, demonstrates how to bind WPF controls to an entity data model, using Visual Studio 2010 Beta 1. You can also learn more in the topic: Walkthrough: Binding WPF Controls to an Entity Data Model.

Binding the multiple drop down boxes in GridView using JQuery in ASP.NET

Here is the code for binding the multiple drop down boxes in GridView using JQuery in ASP.NET

Binding WPF Controls to an Entity Data Model

In this interview, programming writer, McLean Schofield, demonstrates how to bind WPF controls to an entity data model, using Visual Studio 2010 Beta 1. You can also learn more in the topic: Walkthrough: Binding WPF Controls to an Entity Data Model.

WPF / Silverlight tutorial: Visibility property and binding

Visibility property is a very powerful and yet often overlooked property available in both WPF and Silverlight. It enables you to set Visibility of certain UIElement objects to different states like: Visible, Collapsed and Hidden (not supported by Silverlight). This tutorial shows you how to use it and how to bind to Visibility property

Binding an array to dropdown list


I have the following string which is a list of urls. How do I get this to work so the url shows for the selection and also is the value?      


allLinks = newAllLinks
        Me.DropDownList1.DataTextField = "Link"
        Me.DropDownList1.DataValueField = "LinkURL"
        Me.DropDownList1.Items.Insert(0, New ListItem(" - Select - ", 0))
        Me.DropDownList1.DataSource = allLinks


 ArgumentNullException: Value cannot be null.
Parameter name: container]
   System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName) +121
   System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName, String format) +8

Setting the default start page in godaddy hosting?


 How do you set the start page with godaddy hosting? I can see no way of doing this! You do not seem to have access to the IIS settings that allow you to change it!

Row command working on all rows not selected one?



I have this code that hides a column in a gridview.  (The column houses another nested gridview).

    Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
        If e.CommandName = "Select" Then
            If GridView1.Columns(0).Visible = False Then
                GridView1.Columns(0).Visible = True
                GridView1.Columns(0).Visible = False
            End If
        End If
    End Sub

The trouble is that if I click the select link on one row that action to hide is carried out on all rows.  How can I set this up so that it only hides the row that is selected?


Binding Nested Listviews in MVC ViewPage


I am a longtime .NET developer but for big applications and services.  This is my first asp.net project and I have chosen MVC.   I have a need for nesting a ListView within a ListView.  In this simple catalog app, I have EF 4 Entities that are Categories, SubCategories, ItemTypes, and Items.

My goal is to display a 5 column layout of SubCategories with their ItemTypes below them in a ViewPage.  I did just fine with it done out in C# as server directives such as:

    var subcats = Model.SubCategory.ToArray();
    var nrSubCats = subcats.Count();
    var rows = (nrSubCats/5) + (((nrSubCats % 5) > 0) ? 1 : 0);
    for (var row = 0; row < rows; row++)
    { %>
        <div style="width: 100%; float: left; clear: right;">
        var start = row * 5;
        for (var i = start; (i < start + 5) && (i < nrSubCats); i++)
        var subcat = subcats[i];
            <div style="float: left; clear: right; width: 20%; margin-left: 5;">
                <h2> <%:subcat.Name%></h2>
                    foreach (var its in subcat.ItemType)

Setting Screen Resolution



  I am developing a website in asp.net.How can i make my web pages view same in different screen resolutions.I am using 1024*768 resolution

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