.NET Framework Bookmark and Share   
 index > Windows Presentation Foundation (WPF) > Why Can't I Access the StrokeThickness Property Via Code?
 

Why Can't I Access the StrokeThickness Property Via Code?

Hello.

I have the following Xaml code that defines a Rectangle.

            <Rectangle x:Name="BackgroundBlock" 
                   Style="{StaticResource BackgroundBlockStyle}"
                   Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Grid.RowSpan="5" 
                   RadiusX="0.0625in" RadiusY="0.0625in" 
                   StrokeThickness="1" Stroke="Gray"/>

I need to add a NUnit test to check for the StrokeThickness andhave the following code.
The problem is that I do not have access to theStrokeThickness property.
I verified that Rectangle inherits from the Shape class which inherits from FrameworkElement.

        Assert.AreEqual(0, InternalFrameworkElement("BackgroundBlock").STROKETHICKNESS.ToString())

        Public Function InternalFrameworkElement(ByVal name As String) As FrameworkElement
            Return CType(TestElement.FindName(name), FrameworkElement)
        End Function


What do I need to do to get access to Rectangle "BackgroundBlock"'s StrokeThickness?
Since the Xaml code hass access to it, why can't I reference it in code?

Thanks,
Rita

ritagreen
That's part of the NUint test class - it's just an object of the xaml that I'm testing.

I finally got this to work:
Assert.AreEqual(0, CType(InternalFrameworkElement("BackgroundBlock"), Shapes.Rectangle).StrokeThickness)
  • Marked As Answer byritagreen Tuesday, September 22, 2009 4:41 PM
  •  
ritagreen
You'd probably want to read up on Attached and Dependency properties, you can get the value of the stroke thickness using

double

Thickness = (Double)BackgroundBlock.GetValue(Rectangle.StrokeThicknessProperty);

and set the value using SetValue

Ray M_
Thanks Ray - I received an email notifying me of a response but when I checked the thread I could not see it.
I was able to see your reply in the email though!

My problem with using your suggestion (Thickness = (Double)BackgroundBlock.GetValue(Rectangle.StrokeThicknessProperty);) is that I'm not in the code behind class of the Xaml code. I therefore do not have direct access to Rectangle "BackgroundBlock".

-- Rita
ritagreen
Where does the TestElement member used in the InternalFrameworkElement method come from?
dekurver
That's part of the NUint test class - it's just an object of the xaml that I'm testing.

I finally got this to work:
Assert.AreEqual(0, CType(InternalFrameworkElement("BackgroundBlock"), Shapes.Rectangle).StrokeThickness)
  • Marked As Answer byritagreen Tuesday, September 22, 2009 4:41 PM
  •  
ritagreen

You can use google to search for other answers

Custom Search

More Threads

• WPF and Visual Studio
• How to show Flash(swf/flv) file in WPF application ?
• About the operation of the Popup control
• Inheritance of dependency property within a DataTemplate
• [WPF] Toolbar Overflow Issue (.NET 3.5)
• Dealing with ToolBar overflow and clicking a user control
• Styles
• Mouse Position During Drag-And-Drop
• Cannot check listbox items
• Binding DataTable to GridView - Performance getting worse