This is a migrated thread and some comments may be shown as answers.

Attached Behavior

3 Answers 64 Views
Code Analysis
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jan
Top achievements
Rank 1
Jan asked on 11 Aug 2012, 10:35 PM
Hi,

I started evaluation JustCode and thus far I am very happy with it.

One "Warning" that is reported erroneously IMHO is a XAML warning for "XAML: Unknown property 'X' of type 'Foo'"

This happens if I define a standard Attached Behavior as follows:

public class Foo
{
    public static readonly DependencyProperty XProperty =
        DependencyPropery.RegisterAttached
             ("X", typeof(object), typeof(Foo), new UIPropertyMetaData(null));
 
    public static void SetX(DependencyObject target, object value)
    {
         target.SetValue(XProperty, value);
    }
 
    public static void GetX(DependencyObject target)
    {
        return target.GetValue(XProperty);
    }
}


I hope there are no nasty typos in the above example. We now have a basic attached property wrapped in a class. This behavior obviously does nothing, but we don't need that for the example.

JustCode will now generate the warning cited above (namespacing etc. omitted for brevity)
XAML: Unknown property 'X' of type 'Foo'

The issue is obviously that JustCode is looking for the CLR properties to back the X property - but those are not present in the case of attached properties / attached behaviors.
See also http://msdn.microsoft.com/en-us/library/ms749011.aspx 

Or am I missing something really basic here.

Cheers,
Jan

3 Answers, 1 is accepted

Sort by
0
Ivan
Telerik team
answered on 14 Aug 2012, 08:05 AM
Hi,

Thank you for your feedback. I tried to reproduce your issue, but I was not able to.
Could you try refreshing the code analysis from JustCode->Analysis->Refresh Code Analysis. If the warning is still shown after the refresh, could you send me a sample solution that reproduces this issue?
Thank you for your help!

All the best,
Ivan
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Jan
Top achievements
Rank 1
answered on 14 Aug 2012, 10:57 AM
Upon further investigation, the warning occurs with write-only Dependency properties.

I sat down and created an example for you to see -- attached.

Rename the attached file to zip -- it contains the example solution that ehibits the problem boiled down very narrowly.

Cheers,
Jan

PS: doesn't let me attach zip files or a renamed zip file;
so here's the code:

Maindow.xaml
<Window x:Class="WpfApplication1.MainWindow"
        xmlns:ab="clr-namespace:AttachedBehaviors"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <TextBox x:Name="m_tb1"/>
        <TextBox ab:SomeBehavior.X="{Binding m_tb1}"/>
    </Grid>
</Window>

SomeBehavior.cs
namespace AttachedBehaviors
{
    using System;
    using System.Linq;
    using System.Windows;
 
    public class SomeBehavior
    {
        public static readonly DependencyProperty XProperty =
            DependencyProperty.RegisterAttached("X", typeof(UIElement), typeof(SomeBehavior), new UIPropertyMetadata(XChanged));
 
        public static void SetX(DependencyObject target, UIElement value)
        {
            target.SetValue(XProperty, value);
        }
 
        private static void XChanged(DependencyObject target, DependencyPropertyChangedEventArgs e)
        {
            // do things :)
        }
    }
}

All other code was unchanged from the WPF app skeleton.

Cheers,
Jan
0
Svetlozar
Telerik team
answered on 17 Aug 2012, 01:54 PM
Hello,

Thank you for the example provided! I logged it in our system for further investigation.

All the best,
Svetlozar
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
Code Analysis
Asked by
Jan
Top achievements
Rank 1
Answers by
Ivan
Telerik team
Jan
Top achievements
Rank 1
Svetlozar
Telerik team
Share this question
or