Skip to content

Update custom-attached-properties.md #5457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: docs
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 54 additions & 13 deletions uwp/xaml-platform/custom-attached-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,25 +126,66 @@ namespace UserAndCustomControls
}

// GameService.h
...
static Windows::UI::Xaml::DependencyProperty IsMovableProperty() { return m_IsMovableProperty; }
static bool GetIsMovable(Windows::UI::Xaml::DependencyObject const& target) { return winrt::unbox_value<bool>(target.GetValue(m_IsMovableProperty)); }
static void SetIsMovable(Windows::UI::Xaml::DependencyObject const& target, bool value) { target.SetValue(m_IsMovableProperty, winrt::box_value(value)); }
#pragma once
#include "UserAndCustomControls.GameService.g.h"


namespace winrt::UserAndCustomControls::implementation
{
struct GameService : GameServiceT<GameService>
{
GameService() = default;

static winrt::Windows::UI::Xaml::DependencyProperty IsMovableProperty();
static bool GetIsMovable(winrt::Windows::UI::Xaml::DependencyObject const& target);
static void SetIsMovable(winrt::Windows::UI::Xaml::DependencyObject const& target, bool value);

private:

static Windows::UI::Xaml::DependencyProperty m_IsMovableProperty;
};
}
namespace winrt::UserAndCustomControls::factory_implementation
{
struct GameService : GameServiceT<GameService, implementation::GameService>
{
};
}

private:
static Windows::UI::Xaml::DependencyProperty m_IsMovableProperty;
...

// GameService.cpp
...
Windows::UI::Xaml::DependencyProperty GameService::m_IsMovableProperty =
Windows::UI::Xaml::DependencyProperty::RegisterAttached(
L"IsMovable",
winrt::xaml_typename<bool>(),
winrt::xaml_typename<UserAndCustomControls::GameService>(),
Windows::UI::Xaml::PropertyMetadata{ winrt::box_value(false) }
);
#include "pch.h"
#include "UserAndCustomControls.GameService.h"
#include "UserAndCustomControls.GameService.g.cpp"
#include <winrt/Windows.UI.Xaml.Interop.h>

namespace winrt::UserAndCustomControls::implementation
{
winrt::Windows::UI::Xaml::DependencyProperty GameService::IsMovableProperty()
{
return m_IsMovableProperty;
}
bool GameService::GetIsMovable(winrt::Windows::UI::Xaml::DependencyObject const& target)
{
return winrt::unbox_value<bool>(target.GetValue(m_IsMovableProperty));
}
void GameService::SetIsMovable(winrt::Windows::UI::Xaml::DependencyObject const& target, bool value)
{
target.SetValue(m_IsMovableProperty, winrt::box_value(value));
}
Windows::UI::Xaml::DependencyProperty GameService::m_IsMovableProperty =
Windows::UI::Xaml::DependencyProperty::RegisterAttached(
L"IsMovable",
winrt::xaml_typename<bool>(),
winrt::xaml_typename<UserAndCustomControls::GameService>(),
Windows::UI::Xaml::PropertyMetadata{ winrt::box_value(false) }
);
}

...

```

```cpp
Expand Down