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


Top 5 Contributors of the Month
Sharon Maxwell
Post New Web Links

XAML UserControl ItemTemplate Binding does not work

Posted By:      Posted Date: October 22, 2010    Points: 0   Category :WPF
 
Hi there!

I have defined a UserControl to implement a Checkboxed Combobox following the post of justguy:

<UserControl x:Class="KittyUserControlLibrary.ComboWithCheckboxes"
    ...
>

    <UserControl.Resources>
        ...
    </UserControl.Resources>

    <ComboBox
        ...
        IsSynchronizedWithCurrentItem="True"
        ItemsSource="{Binding ElementName=UserControl, Path=ItemsSource}"
        DataContext="{Binding ElementName=UserControl, Path=DataContext}"
        >

        <ComboBox.ItemTemplate>
            <HierarchicalDataTemplate>
                <CheckBox Content="{Binding Title}"
                          IsChecked="{Binding Path=IsSelected, Mode=TwoWay}"
                          Tag="{RelativeSource FindAncestor, AncestorType={x:Type ComboBox}}"
                          Click="CheckBox_Click"
                          />
            </HierarchicalDataTemplate>
        </ComboBox.ItemTemplate>

        <ComboBox.Template>
            <ControlTemplate TargetType="ComboBox">
                &l


View Complete Post


More Related Resource Links

How to load a usercontrol xaml at runtime ???????

  
Hi, I have a usercontrol xaml created in Expression Blend. Similarly i have xaml for other usercontrols as well. Now i want to draw these controls at runtime on click of buttons, the way it works in VS IDE (Toolbox and Drawing area) Is there any way to load such usercontrols on Canvas at runtime ? What would be the best way to load controls at runtime ?      Programmer

How to set Panel.Zindex value though XAML code if any of the Grid/UserControl children having the fo

  
Hi, I have a Grid with 10 buttons. If any of these buttons has focus then I want to set the Panel.Zindex = 999 for the Grid. How to do this in XAML code?Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This will help other members to find the solution easily.

Data binding without typing out xaml

  
Now I'm not stumped on getting data binding to work, I simply want to know how to utilize the window interfaces that visual studio 2010 comes with - as opposed to typing in XAML.  All I want to do is bind a font size property to an xml file within the project.   Here's what I do: After selecting the text box, in the properties panel, i go to the text category then click on the data-binding icon next to the font size field.  I then click on 'apply data binding', where a small panel pops up.  This is where I become stuck.  It seems like I need a path to the xml file, but I don't know how to add that in without typing in XAML.  I would assume that I would be able to add in a resource somewhere - kind of like windows forms allow me to do. I've never worked with WPF before, so I know it's something small/simple that i'm missing.  Any help would be appreciated. thanks, Phil

Data binding without typing out xaml

  
Now I'm not stumped on getting data binding to work, I simply want to know how to utilize the window interfaces that visual studio 2010 comes with - as opposed to typing in XAML.  All I want to do is bind a font size property to an xml file within the project.   Here's what I do: After selecting the text box, in the properties panel, i go to the text category then click on the data-binding icon next to the font size field.  I then click on 'apply data binding', where a small panel pops up.  This is where I become stuck.  It seems like I need a path to the xml file, but I don't know how to add that in without typing in XAML.  I would assume that I would be able to add in a resource somewhere - kind of like windows forms allow me to do. I've never worked with WPF before, so I know it's something small/simple that i'm missing.  Any help would be appreciated. thanks, Phil

Binding UserControl property to Page property

  
So what I'm trying to accomplish is this <uc3:UserControl ID="UserControl 1" runat="server" ClockNumber='<%=ClockNumber %>' Month='<%#Month %>' Year='<%#Year %>' />The user control has public properties named accordingly and the page has protected properties accordingly which I've verified have the desired values.For some reason the values are always empty strings or 0s in the usercontrol, no matter what the page property is.Thanks for any suggestions

Binding a custom type in XAML ?

  
Hi, I'd like to bind a property "myProperty" of type "MyType" in the text property of TextBlock : <TextBlock Text="{Binding myProperty, Mode=OneWay}" And I overrided the ctype operator to have conversion from "MyType" to String: Public Overloads Shared Narrowing Operator CType(ByVal v As MyType) As String ...................... End Operator But it seems not work! I get the ToString of "MyType" in result but not the return of CType operator. Is it normal ? Why ?   Thanks for your help.  

Dynamically Assign Datagrid Column Binding from XAML

  

I am trying to build a generic user control that will serve as a quick list maintenance screen.

I have a base ViewModel that has two string properties IDColumnName and DisplayColumnName and then a collection of objects to be edited.  Inherited view models will be created for each object type that needs to be maintained.  The usercontrols datacontext is set to the viewmodel.

What I want to do is have the datagrid, who's itemssource is bound to the collection of objects in the viewmodel, have one column and have that one column bound to the property specified in the DisplayColumnName property of the viewmodel, and I'd like to do it all in XAML.  I've got the datagrids rowdetailstemplate being dynamically determined based on the object type but am struggling with dynamically setting which property the one column displays.


Binding does not work on wrapped PasswordBox

  

I have wrapped the default PasswordBox with my own PasswordBox code in order to be able to databind the SecurePassword property as it does not have a dependency property on the default PasswordBox.

Everything is going well except one thing, when I type text in the password box, the binding does not work and the password is not set in my ViewModel. I can see when my panel loads that the Password is being retrieved from my ViewModel, and I can also see that my PasswordBox's SecurePassword property setter is being called when I type in the password (so it calls SetValue(SecurePasswordProperty, value), etc.), it just does not make it to the ViewModel at this point.

Any idea why this is working reading from the bound property but not writing to it?

Here is my PasswordBox code:

using System.ComponentModel;
using System.Security;
using System.Windows;
using System.Windows.Controls;

namespace MyNamespace
{

  #region class PasswordBox

  /// <summary>
  /// Wraps the default <see cref="System.Windows.Controls.PasswordBox">PasswordBox</see> control
  /// to make the <see cref="SecurePassword">SecurePassword</see> property bindable.
  /// </summary>
  public partial class PasswordBox : UserControl
  {

    #region Dependency Properties

    public static readonly DependencyProperty SecureP

Inherit UserControl does not work

  

Hi,

I want to inherit from a UserControl, but it is not working :-(

I have a Assembly "MyAssembly". In it I have a Class "MyUserControl" which derives from UserControl (WPF).

Then I have a WPF project where I added a UserControl and changed the XAML and code behind file, so that it derives from MyUserControl.

The problem is, that the designer is not able to show the UserControl (MyUserControl). I do not want to add MyUserControl to a Window! I just want to have directly the MyUserControl and want to add Controls with the Designer or XAML file.

The reason is, that I want to have a UserControl with same basic functionality and this UserControl should be used in any project I want. The base UserControl (MyUserControl) has no XAML code, only some functionality in the class of it.

 

 


Dynamic ItemTemplate binding?

  

Hello,

I defined an ItemTemplate for an object type.

    <DataTemplate x:Key="listViewItemTemplate" DataType="{x:Type model:ParameterWithValue}">
      <DockPanel>
        <Grid DockPanel.Dock="Top" IsEnabled="{Binding Enabled, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}">
When one or more of my objects change their Enabled properties, the layout is not updated... why this?


Inherit UserControl does not work

  

Hi,

I want to inherit from a UserControl, but it is not working :-(

I have a Assembly "MyAssembly". In it I have a Class "MyUserControl" which derives from UserControl (WPF).

Then I have a WPF project where I added a UserControl and changed the XAML and code behind file, so that it derives from MyUserControl.

The problem is, that the designer is not able to show the UserControl (MyUserControl). I do not want to add MyUserControl to a Window! I just want to have directly the MyUserControl and want to add Controls with the Designer or XAML file.

The reason is, that I want to have a UserControl with same basic functionality and this UserControl should be used in any project I want. The base UserControl (MyUserControl) has no XAML code, only some functionality in the class of it.

 

 


Binding Question How does one set datacontext to same class in XAML?

  

I have a usercontrol with one button in it.  I want to set the text via a property getter setter using the INotifyPropertyChanged interface in code behind.  I can get it to work if I set the DATACONTEXT in code behind in the CTOR like this : DataContext = this;  Everything works perfect. 

But here's the problem.  If I try to do this in xaml by defining an XMLNS which points to the folder this usercontrol is in, and then attempt to reference it as a resouce like this <local:XXXXXX  <-------The XXXX which is the class name of this control can't be found?  Is that wierd?  Can't a resource be itself?  So that I can set the Datacontext in the XAML instead of code behind?  I've tried to bind to relative source self, but cannot set the property (Event when I attempted to created a dependency property).....  Just wondering how one sets up Datacontext to the same class? 


Javaman

Referencing a Dependency Property in XAML of parent UserControl where the property setter acceptable

  

I hope that title wasn't too confusing. I'm going to try my hardest to explain what I am trying to do.

I have a child UserControl and parent UserControl. The child UserControl has a Dependency Property that I want to set in my parent UserControl. I want to see the set operation change the child UserControl visually while I change the xaml in the parent UserControl. This setter needs to require that it's value is selected from a specific subset of a set of objects.

How do I accomplish this?

The only thing I can think to do is to specify the name of the object being selected and handle the actual selection of that object in the callback of the dependency property setter.

 


Binding Datatable to listview in Xaml

  

Hi,

  Can any one give me solution for below code.  I know how to bind the datatable to listview in code behind, but  i don't know, how to bind it through XAML. This is my sample code. Please any one help me.

<Window x:Class="ListViewDemo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:ListViewControl;assembly=ListViewControl"
xmlns:local="clr-namespace:ListViewDemo"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<DataTemplate x:Key="checkBox">
<CheckBox IsChecked="{Binding Path=Check, Mode=TwoWay}"/>
</DataTemplate>
</Window.Resources>
<Grid>
<ListView Name="lvProcess">
<ListView.View>
<GridView>
<GridViewColumn Header="Dep_Type" DisplayMemberBinding="{Binding Path=Dep_Type}"/>
<GridViewColumn Header="Check" DisplayMemberBinding="{Binding Path=Check}"/>
<GridViewColumn Header="Depend

Binding an ObservableCollection via XAML without code behind

  

 

I think I am missing something basic here.. But could someone show me what I am doing incorrectly?

MainWindow.xaml.cs

  public partial class MainWindow : Window
  {
    public ObservableCollection<string> TestOC = new ObservableCollection<string> { "First" };

    public MainWindow()
    {
      InitializeComponent();
      TestOC.Add("Second");     
    }

 the XAML file:

<Window x:Class="WpfApplication2.MainWindow"
    ...">
  <Grid>
    <ListView ItemsSource="{Binding TestOC}"/>
  </Grid>
</Window>

Shouldn't that just work?

 

Conditional Binding with XAML

  

Hello,

I have just started to work with silverlight application in Expression Blend 4.

I have a label contains a number, and I want to fill a rectangle with the right color. For example, if the content is above 90 to fill it with green, and so on, but I dont know how to do it.

Thank in advance for your help.


XBAPs and Loose XAML does not work on corporate PCs

  

Hi, I'm a developer who would like to leverage XBAPs for some intranet applications, but I've run into the scenario where neither XBAPs or standalone XAML displays in IE on any of our corporate PCs with .NET 3.0. It doesn't matter how I do it:

  • I can click on an XBAP on the internet, no luck
  • I can click on a Standalone XAML locally/or on the web, no luck
  • I can create a XBAP project in Visual Studio and try and run it, still no luck

I have admin access on my machines so can anyone thing of any reason why this wouldn't work. The ultimate goal is to get this working on user machines,but I have to obviously get it working on a developer machine first.

Not even the simplest helloworld xbap or xaml file works, it seems like an error occurs somewhere in PresentationHost.

 

I got the following error we loose xaml files in IE:

 

Startup URI: D:\DevCode\MSDNMagazine\Foundations\BareBonesProgressBar.xaml
Application Identity: file:///c:/WINDOWS/Microsoft.Net/Framework/v3.0/WPF/XamlViewer/XamlViewer_v0300.xbap#XamlV

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