.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

ICollectionView as DependencyProperty

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

I have a Class with base as TextBox and attach a ICollectionView as DependencyProperty to it.

This ICollectionView has set of information like Width, Height, Allignment etc. which i got from the database.

I bind this ICollectionView to a ListView where i am able to update the ICollectionView items.

This is Working fine.

But my problem is to update the Controls Original Property with this ICollecitonView

ie, If ICollectionView has an Item Called 'Width' in it

is it possible to update the Controls Original Property while changing the 'Width' Item in ICollectionView

Pls Help...


View Complete Post

More Related Resource Links

register DependencyProperty



I Used to add Controls Dynamically at runtime.

My Question is .

Is it possible to add DependencyProperty dynamically at run time.

DependencyProperty Default Value



I created a DP that needs to be initialized with a certain instance in my Window.

How can I pass that instance into the constructor of my DependencyProperty's Type??

Here is a sample code:

public partial class Window1 : Window
    private ClassA _classA;

    public Window1()

    public ClassB Sample
        get { return (ClassB)GetValue(SampleProperty); }
        set { SetValue(SampleProperty, value); }

    // Using a DependencyProperty as the backing store for ClassClassB.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty SampleProperty =
        DependencyProperty.Register("Sample", typeof(ClassB), typeof(Window1), new UIPropertyMetadata(new ClassB(_classA)));

public class ClassA
    public ClassA()

public class ClassB
    private ClassA _classA;

    public ClassB(ClassA classA)
        _classA = classA;

I get an error because _classA is not static...

any ideas?



Style Trigger On Custom DependencyProperty


Hello all.

I'm having trouble setting a Style Trigger on a custom DependencyProperty I have set up in a UserControl.

Here is my "DragWidth.xaml":

<UserControl x:Class="TouchScreenTest.Controls.DragWidget"

ICollectionView grouping


I have virtual IList<T> implementation (Db4oList) for db4o (www.db4o.com) object database and want to add ICollectionView implementation.

I have described one problem with ObservableCollection here:


But there is also related problem:

Db4oList keeps only specified amount of objects in memory.

E.g. say I have 1 000 000 objects (items) in it loaded from db4o database. I keep only 1 000 of them in memory when enumerating the list or using its indexer to access items.

I have no problem with sorting or filtering, but the problem is with grouping, because when ICollection.Groups could have too many objects and because it is defined as ReadOnlyObservableCollection<object> I cannot use a virtual IList<T> implementation for groups, because there is only constructor which accepts List<T> object.

That is why I think (ReadOnly)ObservableCollection<T> should have constructor for  IList<T> object or use ICollection<T>/IList<T> type for ICollection.Groups property, otherwise it won`t be usefull

Attached DependencyProperty and generic styles


Hi All,

I created an attached dependency property, let's say "MyProperty.MyAttachedDependencyProperty".
When I use this attached dependency properties straight on a control, everything works fine.

For instance:


<TextBox MyProperty.MyAttachedDependencyProperty="True" Text="SomeText" />


Now, I want to assign this value for my attached dependency property in a style.
I know it should be possible to set values for attached dependency properties in style, because for instance
the System.Windows.Controls.Validation.ErrorTemplate attached dependency property can be set in style as well.

So I create my style like this:

<Style x:Key="MyStyle" TargetType="{x:Type TextBox}">
  <Setter Property="MyProperty.MyAttachedDependencyProperty" Value="True"/>


<TextBox Style="{StaticResource MyStyle}" Text="SomeText" />



Then I get an exception saying:

'Set property 'System.Windows.Setter.Property' threw an exception.' Line number '46' and line position '14'.
"Value cannot be null.\r\nParameter name: property"

   at System.Win

How do I do a simple DependencyProperty?


I have been reading about Dependency Properties, but haven’t come across a code example for what I am trying to do. Is there a way I can use them so that when m_iChangeableVar changes, SetNewText() gets called? (Having the desired symbols in scope is not an issue.) Note that the variable that changes is autogenerated from an .xsd file. (If that makes it impossible to do what I want, I’d still be interested in how to code it the most elegantly if the var wasn’t auto-generated.)


    <xs:element name="m_iChangeableVar" type="

DependencyProperty.Register returns null?



I have the following code for registering a DependencyProperty of type Type:

 metadata = new
                                                                              FrameworkPropertyMetadataOptions .None,

My first DependencyProperty cannot be set :(


Hi, I tried to add binding support to the System.Windows.Documents.Run inline element:


Code Snippet

class BindableRun : Run


    public static readonly DependencyProperty BindableTextProperty = DependencyProperty.Register("BindableText", typeof(string), typeof(TextBlock),

new FrameworkPropertyMetadata(string

Best way to hookup a DependencyProperty Callback event handler


I'm just wondering which is the best way to hookup a DependencyProperty's Callback event handler.  The two methods that I'm debating over are:


Method 1 - Use static event hanlders, like so:

public virtual int SelectedID<br/>
	get { return (int)GetValue(SelectedIDProperty); }<br/>
	set { SetValue(SelectedIDProperty, value); }<br/>
public static readonly DependencyProperty SelectedIDProperty =<br/>
	DependencyProperty.Register("SelectedID", typeof(int), typeof(SelectorBase), new PropertyMetadata(0, new PropertyChangedCallback(OnSelectedIDChanged)));<br/>
private static void On
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