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

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Setting an attached property by a Setter element?

Posted By:      Posted Date: September 09, 2010    Points: 0   Category :WPF
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="

View Complete Post

More Related Resource Links

Creating a volume control slider/setting one template property based on another

So, what I want to do, is to make a volume control that looks like a right angle triangle with the 90 degree angle on the bottom right, and then when you click on it, the area to the left of the selected point is shown in a different color.  In other words, I've created a slider with the right background, what I can't do, is work out how to show the selected area by filling in the triangle.  I have worked out how to bind the height of my triangle on the left to the value of the control, but right now, the rate of rise is exactly half of what I need it to be.  I need to know how to change the template for the area to the left of the selection ( which is the repeat button ) so that the background is twice the height that it is right now.  No matter what size I make the slider, the area is always 1/2 the size it needs to be, so I am sure if I could get it to double inside my template, it would work fine. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">       <Style x:Key="SliderButtonStyle" TargetType="{x:Type RepeatButton}">         <Setter Property="SnapsToDevicePixels" Value="true"/>         <

How Do I Not Include: myControl.GetType.GetProperty("Text") When No Property Window Setting?

Hi All, Posted below is code I'm using to generate a list of controls that have either a "Text" or "Caption" property. However, for certain controls in the resulting list, the property setting (Text/Caption) does not appear in the "Property Window" of the IDE when that control is selected. One example of this is the Systems.Windows.Forms.PictureBox control. Is there a way I can determine this and if so - how do I exclude these control(s) from my list?     Private Sub cmdValidateControls_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdValidateControls.Click         txtResults.Clear()         For Each ctrl As Object In Me.Controls             LogControl(ctrl)         Next     End Sub     Private Sub LogControl(ByVal ctrlIn As Object)         If System.Diagnostics.Debugger.IsAttached Then             If (Not ctrlIn.GetType.GetProperty("Text") Is Nothing) Or (Not ctrlIn.GetType.GetProperty("Caption") Is Nothing) Then                 txtRes

Dynamically Setting the property value FilterValue1 of the Content Query WebPart? Inline? codeblock?

I want to dynamically set the FilterValue1 property of a Content by Query to the querystring ID. I tried to do it with an inline embed FilterValue1="<%= Reponse.Write .. but no luck Without having to code my own webpart, any way to change the value with a small C# code block? How about with javascript? Thank you!    

Setting a Property that causes update on a UpadatePanel on Init stage.

Hi, I have a custom control with a UpdatePanel inside. Depending of user action or page programing I call Update method of my UpdatePanel to refresh html portion to user.For example, I created a property called Title. If the Title change i call Update of my UpdatePanel.public string Title { get { return labelTitle.Text; } set { if (labelTitle.Text != value) { labelTitle.Text = value; panelUpdate.Update(); // Refresh the entire control } } }   But if the Title property is configured on aspx file, my UpdatePanel is always refreshed because my Title property is setted on Init stage of page life cycle.I need to know if this property is setted on init stage or if ViewState is restored to avoid call Update, or any tips to avoid refresh my control everytime. Thanks,Tales Aguiar.

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?

Setting CssClass on every node in TreeView element



I would like to set a class for every node that exists on my treeview, so I can change its appearance through CSS only. The TreeNode element is rendered as a table with <td> and <tr> tags. Basically I would like to add "class" attribute to those tags. 

So far I wasn't able to do that, because I couldn't find a suitable property on the treenode element. There IS a CssClass property on the whole treeview but that doesn't help me at all. Also I noticed the NodeStyle and SelectedNodeStyle properties on the TreeView element, but that means that I would have to change the appearance programatically, not with CSS.

Anyone got any ideas?

property setting in report server (2008) config file is not working as expected.



I have set the <WorkingSetMinimum> property to 2.4GB in my reportserver 2008 config file.

By defintion, <WorkingSetMinimum> setting means,

  1. Lower limit of service memory consumption; memory will not be released if the consumption is below this amount, though the service will not reserve the designated amount of memory when it starts.
  2. If service uses more than the designated amout of memory, it will release back the memory only till this declared value and not beyond that, which means it should keep 2.4GB as designated.

See this link for definition: http://books.google.com/books?id=mzY_Xo_9J-gC&pg=PA589&lpg=PA589&dq=What+is+%3Cworkingsetminimum%3E+in+report+server+configuration+file&source=bl&ots=r_xhRp8erj&sig=E_o0-Dh2SXOgMNrW3sptt5oZrYI&hl=en&ei=f5mjTNeNM5O8ccmErJMI&sa=X&oi=book_result&ct=result&resnum=4&ved=0CCAQ6AEwAw#

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.


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?



Setting property in mother-form ???


I have a form, A, with a property _B and set/get defined as public.

From form A I start another form - a toolbox - where I can choose a value for the property _B in form A.

But how can I set the value I before I close my other form ?

(The set/get does NOT appear !)

Best regards KSor, Denmark

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:

Using markup extension's property as property element


Hello, I am learning WPF and I wonder how to use property of markup extension as property element.

I have this extension, which simply returns what is set to Value property:

namespace Ch2CustomMarkupExtension
  using System;
  using System.Windows.Markup;

  public class MyExtension : MarkupExtension
    public MyExtension()
      this.Value = "undefined";

    public MyExtension(string value)
      this.Value = value;

    public string Value
      get; set;

    public override object ProvideValue(IServiceProvider serviceProvider)

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 ?

SSIS - Setting TablesList Property with expression


I am having problems withing with the Transfer SQL Server Objects task in SSIS.  I would like to set the TablesList Property of the task to the value of an expression.  At a high level, I need to transfer a table from one server to another but the table name is dynamic so I can't use a data flow task.  Each iteration of the package execution will work off of one table so I need to set the TablesList property to the one table. 

Since the property is a collection, I am getting errors when I attempt to just assign the TablesList property to the variable value in the expression builder.  I get this error:

Error at Copy Table To Production: The result of the expression "@[User::TablesList]" on property "TablesList" cannot be written to the property. The expression was evaluated, but cannot be set on the property.

I also tried to open up the SSIS package in textpad and look at the formatting of the TablesList property and then set the variable to match what I saw in the XML......this gave me the same error.

Any suggestions on how to set a StringCollections property in SSIS?

Thanks in advance,


Setting label property in web control


Hello all,

I am converting a 1.1 .NET web app to 3.5, and I've run into a bit of a jam.

One web control has a Property that sets the page title label on that web control.

    Public Overridable Property PageTitle() As String

'Exposes the PageTitle property of the child control.
Return lblPageTitle.Text
End Get

Set(ByVal Value As String)
'TODO: find out why this throws a NullReference exception
lblPageTitle.Text = Value
End Set

End Property

When a page with the web control was loaded before, it would set the Property to a given string, like in ucHeader.PageTitle = "This is a string."  Now, if I don't remove the lblPageTitle.Text = Value, I get a NullReference Exception.  Anyone have any ideas?

Attached Property


I am working a project that has several different controls that I am trying to use an attached property to dictate whether or not to perform a recalculation operation if changed.  I am using what I thought was the standard pattern for the creating of an AP.

    public class RecalcProperty : DependencyObject
        public static readonly DependencyProperty PerformRecalcProperty = DependencyProperty.RegisterAttached(
          new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.None)
        public static void SetPerformRecalc(UIElement element, Boolean value)
            element.SetValue(PerformRecalcProperty, value);

        public static Boolean GetPerformRecalc(UIElement element)

Using an argument in an attached property



I've written a workflow level ErrorMessage as an attached property on the root workflow activity, at design time.  I made the attached property for ErrorMessage written as an InArgument (to support some custom control that works well with InArguments).  Here's some of the design time code:

            AttachedProperty<InArgument<string>> ErrorMessage = new AttachedProperty<InArgument<string>>
                OwnerType = typeof(ActivityBuilder),
                IsBrowsable = true,
                Name = "ErrorMessage",
                Getter = (mi =>
                    InArgument<string> temp;

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