OverMalo
Topic Author
Posts: 5
Joined: 08 Feb 2012, 11:05

UserControl DependencyProperty

24 Feb 2012, 09:46

Hi,

I define a DependencyProperty in UserControl like this:

(Simplify class)
class WorkerOffice : public UserControl
{
public:

NsInt32 GetItemAsked() const
{
  return DependencyObject::GetValue<NsInt32>(ItemAskedProperty);
}

void SetItemAsked(NsInt32 value)
{
  DependencyObject::SetValue<NsInt32>(ItemAskedProperty, value);
}

public:
static const Gui::DependencyProperty* ItemAskedProperty;

private:
  NS_IMPLEMENT_INLINE_REFLECTION(WorkerOffice, UserControl)
  {
    NsMeta<TypeId>("WorkerOffice");
		
    NsProp("ItemAsked", &WorkerOffice::GetItemAsked, &WorkerOffice::SetItemAsked);

    NsString source = "MyApps/CaliforniaOffice/WorkerOffice.xaml";

    Ptr<UIElementData> data = NsMeta<UIElementData>(TypeOf<SelfClass>());

    data->RegisterProperty<NsInt32>(ItemAskedProperty, "ItemAsked",
        FrameworkPropertyMetaData::Create(NsInt32(0)));

    data->OverrideMetadata<NsString>(UserControl::SourceProperty, "Source",
        FrameworkPropertyMetaData::Create(source, FrameworkOptions_None));
    }
};

const DependencyProperty* WorkerOffice::ItemAskedProperty;
In UserControl´s xaml i code:
<UserControl
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  x:Class="WorkerOffice" x:Name="WorkerOffice">
   
  ....
  ....
  
<TextBlock Text="{Binding ItemAsked, ElementName=WorkerOffice}"/>

I obtain an exception building xaml. I attached minidump.
Attachments
20120224094535.Error.rar
(32.73 KiB) Downloaded 282 times
 
OverMalo
Topic Author
Posts: 5
Joined: 08 Feb 2012, 11:05

Re: UserControl DependencyProperty

24 Feb 2012, 09:59

Fixed with:
data->RegisterProperty<NsInt32>(ItemAskedProperty, "ItemAsked",
FrameworkPropertyMetaData::Create(NsInt32(50), FrameworkOptions_None));

Who is online

Users browsing this forum: No registered users and 1 guest