.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

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

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

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.


View Complete Post

More Related Resource Links

Property of a base UserControl it's not handled correctly

Hello,I have a class that is a base class for my server controls. Inside this class I have a property that can take values from an enumeration.public enum PanelModeEnum { Add = 1, Edit = 2, ReadOnly = 3 } public class BaseControl : System.Web.UI.UserControl { #region Event Handling Management #endregion public PanelModeEnum PanelMode { get; set; } public virtual void ChangePanelMode(PanelModeEnum newMode) { this.PanelMode = newMode; } } I have then several user controls that inherits from this BaseControl and that I add into aspx pages declaratively<gsl:PhoneNumberUC ID="ucPhoneDetail" runat="server" PhoneNumberType="Home" />I would like to show one the derived BaseControl classes inside a ModalPopupExtender using server-side code. Before doing this I call the ChangePanelMode with a value from the PanelModeEnumucPhoneDetail.PhoneNumberType = ptype; ucPhoneDetail.ChangePanelMode(PanelModeEnum.Add); this.mpePopupPhone.Show(); But when, inside the inherited user control I check for the PanelMode property likeif (this.PanelMode == PanelModeEnum.Add) { ... } the value of this.PanelMode is always equal to zero. Why?Kindly regards

UserControl with a control property?

Hi... I have defined a UserControl wich needs to reference another control like this: <ctrl:Cook TheList="listView1" DefaultFileName="MyRecipe"></ctrl:Cook> The code behind of the control has the property defined:         public ListView TheList { get; set; } But I have a runtime error saying: 'ListView' type does not have a public TypeConverter class. And in design time I get: Property TheList of type ListView cannot be specified as string.   I know WPF is trying to read a string instead of a ListView, but dont know the magic solution. Maybe a converter? Please suggest the simpler solution you can, because this is not a vital requirement on the app. Thanks in advance for any help  

Setting an attached property by a Setter element?

I have the fragment below as contents of a <Grid> element. The idea is that if the checkbox is checked the <TreeView> element should only span one instead of two columns. When I check the checkbox the background of the treeview turns red, but the treeview continues to span 2 instead of 1 column. It's a bit like the attached property Grid.ColumnSpan does not get assigned by the <Setter Property="Grid.ColumnSpan" Value="1"/> at all. What should I do in order to achieve what I want?Best regards,Henrik Dahl   <TreeView    x:Name="Blas"    ItemsSource="{Binding Path=BlasRoot.Children}" d:LayoutOverrides="Width" Margin="0,0,0,8" Grid.Column="0" Grid.ColumnSpan="2">    <TreeView.Style>       <Style>          <Style.Triggers> <DataTrigger Binding="{Binding ElementName=chkPosition, Path=IsChecked}" Value="True">    <Setter Property="Grid.ColumnSpan" Value="1"/>    <Setter Property="TreeView.Background" Value="Red"/> </DataTrigger>          </Style.Triggers>       </Style>    </TreeView.Style> </TreeView> <CheckBox HorizontalAlignment="Left" Margin="-50,0,0,0" x:Name="chkPosition" VerticalAlignment="Top" Content="

Binding to Dependency property

Dear all I have the follwoing xaml code in my main window : <Label Content="{Binding PlayerCount}" DataContext="{Binding ScatterViewModels}" Grid.Row="2" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="20"/> Then I have a class which is the datacontext of my label and host a dependcy property PlayerCount which is set as follow:  PlayerCount = ((Player)svi.Tag).Count Doing so I cannot get the value in my label, anything wrong with the binding ? thnaks for help regards SergeYour knowledge is enhanced by that of others.

Custom Workflow Activity dependency property FieldNames

I have a custom actvity in VS2008. All is well until I added a new dependancy property like so: public static DependencyProperty EventLookupColumnNameProperty = DependencyProperty.Register("EventLookupColumnName",typeof(string),typeof(FTFSyncEventToAttachmentListItem)); public static DependencyProperty EventLookupColumnIDProperty = DependencyProperty.Register("EventLookupColumnID",typeof(string),typeof(FTFSyncEventToAttachmentListItem)); [Description("Event Lookup Column Name")][DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)][Browsable(true)][ValidationOption(ValidationOption.Required)]public string EventLookupColumnName{get { return ((string)(base.GetValue(EventLookupColumnNameProperty))); }set { base.SetValue(EventLookupColumnNameProperty, value); } [Description("Event Lookup Column ID")][ValidationOption(ValidationOption.Required)][Browsable(true)][DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]public int EventLookupColumnID{get { return ((int)(base.GetValue(EventLookupColumnIDProperty))); }set { base.SetValue(EventLookupColumnIDProperty, value); }}Then in the actions file:    <Action Name="FTF Sync Event To Attachment List Item"   ClassName="DP.Sharepoint.Workflow.FTFSyncEventToAttachmentListItem"   Assembly="DP.Sharepoint.Workflow, Version=, Cultur

Property no visible in XAML

Hi I am using the GroupBar control in WPF. I can access the SelectedItem Property from the CodeBehind in the WPF. But in XAML SelectedItem property is not visible for an access. I need to get the selected Groupbar value from the View to ViewModel through the Binding. How can i achieve this ? Thanks, Velu

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

Adding XAML via control property

Hi, I'm attempting to create a custom chart control that has 1 or many line series within it. My question is, is it possible to create a property of that control, that when checked in the designer, will automatically add the line series xaml within the chart series? For example, if you click on the "Add Test Series" check box, which is of type boolean, it will then add <chartingToolkit:LineSeries /> into the xaml of the control as well as to the series of the control.   <local:TestChartControl> <chartingToolkit:LineSeries /> </local:TestChartControl>     Thanks  

How to make ObservableCollection setter trigger when property value changes?


My class has a property ObservableCollection<MyType>. When any value of MyType changes, I want the setter for my property to be hit. It seems the setter is only hit when the CollectionChanged event is thrown, but in this case the Collection isn't changing, just a value of one of the properties in my Collection. 


Any pointers?

class contains non-dependency-property data members that are DependencyObject objects, you must also


I was reading the article Freezable Objects Overviewand came acrosee the statement

"If  your class contains non-dependency-property data members that are DependencyObject objects, you must also call the OnFreezablePropertyChanged method each time you change on of their values, even if you're setting the member to null. "

I quite do not understand the part about non-dependency-property data members that are DependencyObject objects. Can some one explain exactly what this means? If a data member is derived from the DependencyObject  class how then can the data member be a non dependency property?

I am also trying to locate some source code / project that overrides the OnFreezablePropertyChanged method, and have yet to find any on the interenet.

If anyone know whe

DataTemplate trigger to set templated parent property


Hy everybody,I am struggling with a problem.I basically want to provide a data template for my data model and when a trigger on the view happens,I want to change a property in my data model.I cannot figure out how to tell the Setter that it needs to change a property of the templated parent. Here is how it looks now:

My data model for a "Line" looks like this:


public class LineModel : DependencyObject
    public ushort Value
        return (ushort)base.GetValue(ValueProperty);
        base.SetValue(ValueProperty, value);
    public static DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(ushort), typeof(LineModel));


How to get child property inside parent class, with lambda?


Hi all,

Could you answer me how to do next, please? How to do this with Lambda? Is it possible to delegate some object instance and use its properties and methods in case if this method doesn't know type of delegated object?

class class_a {
    public string getChildData<T> (T dynamicInstance) {
        return dynamicInstance.prop;

class class_b : a {
    public string prop = "prop_b";

class class_c : a {
    public string prop = "prop_c";

var inst_b = new b ();
var inst_c = new c ();

Purpose : to get child property inside parent class?

Thanks, Artem

How do I bind to a style's setter property?


Hello everyone,

   I'm trying to bind a brush property to a style within a datagrid (Infragistics), but this is more of a general WPF question.

I have a view model set as the data context of my user control.  One of the properties is ActiveGridRowColor in my view model.  How can I bind this property to the style in the following XAML?



TextBox shows "old" value after being Coerced when bound to a Dependency Property




I am writing a WPF Custom Control.  I want to be able to limit the input for the DependancyProperty "Text".  I have the OnCoerce event handlers connected and this property is bound to the "Text" property on a TextBox in my content template as shown below:


Code Snippet

<TextBox Name="PART_txtEdit"

Background="{TemplateBinding Background}"

BorderBrush="{TemplateBinding BorderBrush}"

How does TextBlock.Foreground property setter in the style of a Button get applied


I am new to WPF. Could someone please explain how the TextBlock.Foreground property setter in the following code actually affect the colour of the displayed text in the button? As far as I know, there is no property named TextBlock in the Button class.<Window x:

How to set a style's TargetType property in XAML to a Generic Class?


I've just moved to .NET 4.0 / Visual Studio 2010 and am hoping there is a new answer to this question, found on StackOverflow from over a year ago:

Is it possible to set a style's TargetType property in XAML to a Generic Class?

public class Selector<T> : Control { }

and then in xaml

<Style x:TargetType="Selector">
<Setter Property="MyProperty" Value="Green" />

I found this on the WPF Tutorial, and would like to find a similar mechanism for this situation above.

<!-- XAML 2009 -->
<ObservableCollection x:TypeArguments="Employee">
 <l:Employee FirstName="John" Name="Doe" />
 <l:Employee FirstName="Tim" Name="Smith" />
</ObservableCollection />



DataGridColumn CellStyle doesn't work. > The Property Setter "IsReadOnly" cannot be set because it


hello i have the folowing DataGridColumn:

<DataGridTextColumn Header="Number of pipes:" Binding="{Binding Path=Pipes.Count}">
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="IsReadOnly" Value="True"></Setter>


But I get the following error: The Property Setter "IsReadOnly" cannot be set because it does not have an accessible set accessor.


Can anyone help me out ?

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