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


Top 5 Contributors of the Month
Easy Web
Imran Ghani
Post New Web Links

binding to properties inside a datatemplate

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

Hi all

 

Im creating a user control which will act like a border.  I will be able to specify via properties each side of the borders thickness and color.  I am using a DataTemplate for this because I want to be able to specify where I want the content to go inside the user control.

 

My problem is I can’t seem to get the properties iv created in code (get;set) to change the thickness or color or the borders iv created in the xaml file.  Iv tried binding to them in the xaml file however they are not getting called.

 

 

More Related Resource Links

Again, Getting control inside datatemplate from code behind

  
HI, All: This problem comes back to bite me again. I had a similar problem before but I changed the customer control to user control and define the click event in the xaml. But this time I have to stick with the customer control. I searched the internet and there are a lot of examples but in my situation, I still got null object. I have a CUSTOMER control which derives from treeview. The hierachicalDataTemplate for the treeview is following:     <HierarchicalDataTemplate         x:Key="CheckBoxItemTemplate"         ItemsSource="{Binding SubFolder}"         >         <StackPanel Orientation="Horizontal">             <CheckBox             x:Name="PART_CheckBox"             Focusable="False"             IsChecked="{Binding IsSelected}"             VerticalAlignment="Center"                 &nbs

Windows Workflow : Activity Binding Properties Window Ellipses button not visible for one property

  
I have created a custom activity, when I am using this activity in workflow designer I am not getting the ellipsis button to select a property.  I am getting the ellipses button for first property LongValue while not getting the option for "NavigationUrl" property. This is the code for my custom activity. public partial class SetLongAsResult: Activity {         public SetLongAsResult() { InitializeComponent(); }         public static DependencyProperty LongValueProperty = DependencyProperty.Register("LongValue", typeof(long), typeof(SetLongAsResult));           public static DependencyProperty NavigationUrlProperty = DependencyProperty.Register("NavigationUrl", typeof(string), typeof(SetLongAsResult));           [Description("long value to be returned")]         [Category("Set Result Data")]         [BrowsableAttribute(true)]         [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]         public long LongValue         {             get             {         

binding datetimecontrol,dropdown,textbox inside gridview and update each gridviewrow

  
i have a web part with datetimecontrol(sharepoint) inside a  gridview. when the page loads this this gridview will be loaded with dtc control and the selecteddate would be one of the columns in the splist.also gridview contaisn dropdowns, textboxes, when an update button cliked inside grid, i need to save the info in the splist.  currently i am not getting the value  bound with dtc control. i am getting blank date inside dtc. though in the  rowdatabound event i amcapturing the values due to some reason i am not able to view the value in the DTCcontrol. can anybody give me help me how to achieve this? any  help links/ sample code.. appreciate the help                         

Some Useful Properties of Binding Class

  
When binding the UI control with the data source the Binding class has some useful properties.In this post we will look at them and use them in sample application. The properties which we are going to discuss in this post are the FallbackValue ,TargetNullValue, and StringFormat. Image 1 shows the output of the example code.

Problem binding business objects to custom user control properties

  
I have created a user control (supplierPicker) intended to allows a supplier database to be searched and a supplier selected. I want to be able to use this control in a number of other user controls, by binding the suppplierID property of the supplierPicker to a supplierID property in a business object, which is set as the datacontext of the parent user control. When I do this, and there is a supplierID specified in the business ofbject, the binding sets the supplierID in the supplierPicker control and it shows the correct supplier name in the textbox. However when the supplierID DependencyProperty is changed from within the supplierPicker the newly selected supplier name is shown in the TextBox, but the SupplierID does not propogate back to the business object. Other controls on the parent form work fine, so the binding to the business object seems to be ok. Any pointers as to what I'm doing wrong here would be grately appreciated.  This one has been driving me nuts for days! Snipped code for the supplier picker:         public partial class SupplierPicker : UserControl, INotifyPropertyChanged     {         public static DependencyProperty SupplierIDProperty;         public event PropertyChangedEventHandler PropertyChan

Click.CommandParameter null when binding on Button inside DataGrid DataGridTemplateColumn

  
I am having trouble getting a Click.CommandParameter to pass through with a bound Click.Command. I have a DataGrid with a DataGridTemplateColumn that contains a couple of Buttons. Using a suggestion found on the forum (http://social.msdn.microsoft.com/Forums/en/wpf/thread/541024a9-3d7e-4c6a-b88e-9a7eb7ee83a9), I was able to get the Click.Command to bind to the right command, but when arriving in the corresponding method in my ViewModel, the parameter is null.  Here is my xaml for my DataGridTemplateColumn <data:DataGridTemplateColumn Header="Case">  <data:DataGridTemplateColumn.CellTemplate>   <DataTemplate >    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">     <Button Content="Open" Margin="6,0" command:Click.Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type data:DataGrid}}, Path=DataContext.OpenCaseCommand}" CommandParameter="{Binding}"  />     <Path Data="M1,1 L1,2" Stroke="#FFCCCCCC"/>     <Button Content="Rename" />    </StackPanel>   </DataTemplate>  </data:DataGridTemplateColumn.CellTemplate> </data:DataGridTemplateColumn> I used Snoop to see what was going on. Everything

How to expose app.config or binding properties for web service

  
I have a project that consumes a web service, which is then bundled into a windows service and a deployment project.  Both the project consuming the web service (I'll call that the vendorcontrol) and the service project have app.config files in the project structure, but when I compile and deploy, the settings for the vendorcontrol are not accessible in the resulting project.exe.config file.  How would I make this happen?

Tab Panel inside a User control - null referance to text box with set properties

  
Hi guys, Im having problems with the following: I have a user control which has a tabbed panel inside, I then have a public property which populates a textbox inside the tabbed panel, HOWEVER when I access the property on my ASPX page, it give me a null referance to textbox, I have tried using findControl but still finds nothing, Please help!! ASPX PAGE  <Registration:UserDetails UserID="23" ID="RegistrationUserDetails" runat="server" /> USER CONTROL<cc1:TabContainer ID="TabContainerRegistration" runat="server" ActiveTabIndex="1" > <cc1:TabPanel runat="server" ID="TabPanelAccessDetails" HeaderText="Access details"> <ContentTemplate> <table> <tr> <td>User ID</td> </tr> <tr> <td><asp:TextBox ID="UserIDTextBox" ReadOnly="true" runat="server" SkinID="InputBoxes"></asp:TextBox></td> </tr> </table> </ContentTemplate> </cc1:TabPanel> </cc1:TabContainer> CODE BEHINDprivate int _UserID; public int UserID { set { TextBox tb = (TextBox)TabContainerRegistration.

DataTemplate binding based on object property

  

I have a collection of objects that I'm giving visual representation in my UI through DataTemplates. Each object has a string property "field". 

Is it possible for my UI to exclude specific objects in my collection from being shown based on the "field" property if it contains a string "foo"? 

 

 


Using MVVM and commands inside of a datatemplate, the command wont execute.

  
Inside of my main view i have a datatemplate showing off all the items in an observable collection. now inside of that i want to set commanding on a radio button.

outside the datatemplate this works
<Button Height="23" Name="btnUpdate" Command="{Binding UpdateCommand}"

UserControl in DataTemplate for a GridViewColumn data binding

  

Hey guys,

I have a UserControl with a TextBox in it (in my app, it's a little more than a text box - but for reproducing I used the textbox). This UC is put inside a DataTemplate for a GridViewColumn cell template. Below is  the UC.

<UserControl x:Class="XXX.TestUC"
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" <span style="font-family:Verdana,Arial,Helvetica,sans-serif; white-space:normal; color:#8b008b">xmlns:<span style=

WPF Toolkit Calendar, Blackout Dates, DataTemplate, Binding, MVVM

  

Hi!

I am building an application using the MVVM model and I'd like to bind a calendar's "BlackoutDates" collection. I found this interesting piece of code which shows how to achieve this binding through an Attached Property. I am using the WPF ToolKit at codeplex.

However as I understand it, I need to bind to a "CalendarBlackoutDatesCollection" property. Ideally, this property would be in my ViewModel so that i can use {Binding BlackoutDates} however, the constructor for CalendarBlackoutDatesCollection has to specify the "owner", or the calendar that will receive this collection, which my ViewModel doesn't know about.

The calendar is actually part of a DataTemplate so I can't just name it and reference it directly. I'm saying this because I tried a workaround solution through events in the code behind file. The simplest of my scenario involves 2 calendars in the same data item (a "from" and a "to" calendar). When the user clicks on a "From" date, then all prior dates are blacked out in the "To" calendar to prevent the user from entering a time range backwards. The same applies if a user selects a "To" date - anything after that

Is it a bug in Visual Studio 2008 in WPF Designer when binding to enum defined inside of class?

  

Hello,

 

I have following problem:

when defining an enumeration inside of class (either static class or not) I can bind to this enum, however the WPF Designer inside Visual Studio does not display designed GUI anymore and show an error Type "MyClass+MyEnum" was not found.

However I can compile and execute the code and in the combobox all enum- values are listed.

 

Code behind:

    public class MyClass
    {
        public enum MyEnum { enumValue01, enumValue02, enumValue03, enumValue04, enumValue05 }
    }

 

My xaml-code:

<Window x:Class="SampleBindingOfNestedEnumToComboBox.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"          
    xmlns:local="clr-namespace:SampleBindingOfNestedEnumToComboBox"
    Title="Window1" Height="300" Width="300">

    <Window.Resources>

Is it a bug in Visual Studio 2008 in WPF Designer when binding to enum defined inside of class?

  

Hello,

 

I have following problem:

when defining an enumeration inside of class (either static class or not) I can bind to this enum, however the WPF Designer inside Visual Studio does not display designed GUI anymore and show an error Type "MyClass+MyEnum" was not found.

However I can compile and execute the code and in the combobox all enum- values are listed.

 

Code behind:

  public class MyClass
  {
    public enum MyEnum { enumValue01, enumValue02, enumValue03, enumValue04, enumValue05 }
  }

 

My xaml-code:

<Window x:Class="SampleBindingOfNestedEnumToComboBox.Window1"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:sys="clr-namespace:System;assembly=mscorlib"     
  xmlns:local="clr-namespace:SampleBindingOfNestedEnumToComboBox"
  Title="Window1" Height="300" Width="300">

  <Window.Resources>
    <ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type sys:Enum}" x:Key="odp">
      <ObjectDataProvider.MethodParameters>
        <x:Type TypeName="local:MyClass+MyEnum"/>
      <

Combobox inside Listbox binding issue

  
I am lost...

I have the following two classes (simplified)

Class Parent
{
    String Description{get;set;} 
    ObservableCollection<Children> ListOfChildren = new ObservableCollection<Children>();
}

Class Children
{
    public string Name{get;set;}
}

And the following two lists :

public List<Parent> ListOfParents = new List<Parent>();
public static List<Children> StaticListOfChildren=new List<Children>();


Now I have a list in XAML, I set the datacontext of this list to the "ListOfParents" (in code) and set the ItemSource="{Binding}"
All works fine so far. Inside this list I have another list containing the "ListOfChildren" list. The itemtemplate of this list contains a combobox. This combobox binds to the "StaticListOfChildren" list. The problem is now I can't get the selecteditem of the combobox to bind to the Children item in the ListOfChildren.... Can anyone help ??

<ListBox x:Name="lbMaterialsBuildup" HorizontalContentAlignment="Stretch" ItemsSource="{Binding}">
    <ListBox.ItemTemplate>
        <DataTemplate>
&nb

binding usercontrol elements properties

  

I am desperatly trying to understand bindings in WPF, I would like to understand how I can bind the elements of 2 Usercontrols to each other, so that if I change the value of the slider the circle strokethickness changes and if I change the circle strokethickness the slider changes. I have some code that hopefully explains what I want to understand better. TIA Mike

<Window x:Class="WpfDependencyTest.MainWindow"

  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

  xmlns:local="clr-namespace:WpfDependencyTest" 

  xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" 

  xmlns:ei="clr-namespace:Microsoft.Expression.Interactivity.Layout;assembly=Microsoft.Expression.Interactions" 

  Title="MainWindow" Height="350" Width="525">

 <Grid>

  <local:UcCircleText ></local:UcCircleText>

  <StackPanel Height="Auto" HorizontalAlignment="Right" x:Name="stackPanel1" VerticalAlignment="Bottom" Width="Auto" Background="Aqua">

   <local:UcSlider Height="150" Width="150"></local:UcSlider>

   <i:Interaction.Behaviors>

    <ei:MouseDragElem

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.
Categories: 
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